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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Javier Quarite at Feb 16, 2012 at 6:22 pm
    Maybe this can help you

    http://railscasts.com/episodes/111-advanced-search-form

    Javier Q.

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
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 © 2021 Grokbase