Is it possible to do 3 separate search forms in one model and view?
at present I have the following in my view:
<%= form_tag games_path, :method => 'get' do %>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search", :game_name => nil %>
<% end %>
and the following in my model:
def self.search(search)
if search
find(:all, :conditions => ['game_name LIKE ? OR genre LIKE ? OR console LIKE ?', "%# {search}%", "%#{search}%", "%#{search}%"])
else
find(:all)
end
end
What I want to do is separate the model in to three parts so that it is not all in one form e.g.
def self.search(search)
if search
find(:all, :conditions => ['genre LIKE ?', "%#{search}%"])
else
find(:all)
end
end
def self.search(search)
if search
find(:all, :conditions => ['console LIKE ?', "%#{search}%"])
else
find(:all)
end
end
def self.search(search)
if search
find(:all, :conditions => ['game_name LIKE ?', "%#{search}%")
else
find(:all)
end
end
and then in my view have x3 of my above view code so that there is one search for name, one for console and one for genre? How would I go about doing this? I hope this makes sense.
This kind of stuff becomes quickly a mess. For this very reasons, you should go for a more maintainable solution with the help of a gem like meta_search.