Hi all, I am wondering if any of you know how to make multiple search
methods in one model?

currently I have a search method that has been declared in the model,
but I want to create another separate search for different criteria in
the database table. How would I do that?

I currently have the following in my games.rb

def self.search(search)
if search
find(:all, :conditions => ['game_name LIKE ?', "%#{search}%"])
else
find(:all)
end
end

the following in my games_controller.rb

def index
@games = Game.search(params[:search])
end

and the following in my index.html.erb

<%= form_tag games_path, :method => 'get' do %>

<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search", :game_name => nil %>

<% end %>

Any help would be much appreciated.
Thanks

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 2 | next ›
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedFeb 16, '12 at 4:44p
activeFeb 16, '12 at 6:22p
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2023 Grokbase