Posted by
alvin2ye
on
August 25, 2010
use OpenStruct when advance search
Before
in view
<% form_for_tag blabal do |f| %>
<%= f.text_field_tag :quick, params[:search][:quick] %>
<%= select_tag("country", options_for_select([["unassigned" , "0" ]] +
Country.to_dropdown, region.country_id),
{:name => "search[country]"} ) %>
<%= f.submit "Search" %>
<% end %>
After
in controller
require 'ostruct'
def index
@search = OpenStruct.new(params[:search])
end
in view
<% form_for :search, :url => {:action => "index"}, :html => {:method => :get} do |f| %>
<%= f.text_field :quick %>
<%= f.select :quick, Country.to_dropdown %>
<%= f.submit "Search" %>
<% end %>

Comments
it cleans up your code too, you dont' have to specify the hash key everywhere repeatedly in your code.
to me, it is more object-oriented-looking.
It would be great if you could modify this post into something like this:
Before
...After
...I miss the "Before" section...