# Multiple search methods

**URL:** <https://discuss.rubyonrails.org/t/multiple-search-methods/62855>\
**Category:** rubyonrails-talk\
**Created:** [February 16, 2012, 4:44pm UTC](https://discuss.rubyonrails.org/t/multiple-search-methods/62855 "2012-02-16T16:44:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [February 16, 2012, 4:44pm UTC](https://discuss.rubyonrails.org/t/multiple-search-methods/62855/1 "2012-02-16T16:44:14Z")

</div>

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

&nbsp;&nbsp;def self.search(search) &nbsp;&nbsp;if search &nbsp;&nbsp;&nbsp;&nbsp;find(:all, :conditions =\> ['game\_name LIKE ?', "%#{search}%"]) &nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;find(:all) &nbsp;&nbsp;end end

the following in my games\_controller.rb

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

and the following in my index.html.erb

\<%= form\_tag games\_path, :method =\> 'get' do %\>

&nbsp;&nbsp;&nbsp;&nbsp;\<%= text\_field\_tag :search, params[:search] %\> &nbsp;&nbsp;&nbsp;&nbsp;\<%= submit\_tag "Search", :game\_name =\> nil %\>

\<% end %\>

Any help would be much appreciated. Thanks

---

<div class="post-metadata">

**Author:** ![Javier\_Quarite](https://avatars.discourse-cdn.com/v4/letter/j/848f3c/32.png) [@Javier\_Quarite](https://discuss.rubyonrails.org/u/Javier_Quarite)\
**Post date:** [February 16, 2012, 6:21pm UTC](https://discuss.rubyonrails.org/t/multiple-search-methods/62855/2 "2012-02-16T18:21:53Z")

</div>

Maybe this can help you

[http://railscasts.com/episodes/111-advanced-search-form](http://railscasts.com/episodes/111-advanced-search-form)

Javier Q.
