# Search area

**URL:** <https://www.ruby-forum.com/t/search-area/191513>\
**Category:** Rails\
**Created:** [July 13, 2010, 6:59pm UTC](https://www.ruby-forum.com/t/search-area/191513 "2010-07-13T18:59:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anat42000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7ea924/32.png) [@anat42000](https://www.ruby-forum.com/u/anat42000)\
**Post date:** [July 13, 2010, 6:59pm UTC](https://www.ruby-forum.com/t/search-area/191513/1 "2010-07-13T18:59:36Z")

</div>

Hi,

I’ve implemented two boxes of research which correspond to two columns  
of my table. This solution works well:

In my index.html.erb:  
\<% form\_tag search\_intervenants\_path, :method =\> :get do %\>  
\<%= label\_tag “code” %\>  
\<%= text\_field\_tag “search[by\_code]”, params[:search].try(:  
[], :code) %\>  
\<%= label\_tag “id” %\>  
\<%= text\_field\_tag “search[by\_id]”, params[:search].try(:[], :id) %\>  
\<%= submit\_tag “Search” %\>  
\<% end %\>

In my controller:  
def search  
@intervenants = Intervenant.search(params[:search])  
render :index  
end

In my model:  
def self.search(params)  
params.keys.inject(scoped({})) do |found, k|  
params[k].blank? ? found : found.send(:"#{k}", params[k])  
end  
end  
scope :by\_code, lambda {|name| where(“intervenants.code LIKE ?”,  
“%#{name}%”)}  
scope :by\_id, lambda {|name| where(“intervenants.id LIKE ?”,  
“%#{name}%”)}

I would like to have an only search area, I tried but I didn’t suceed  
in it… Who can help me? Thanks a lot !

---

<div class="post-metadata">

**Author:** ![anat42000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7ea924/32.png) [@anat42000](https://www.ruby-forum.com/u/anat42000)\
**Post date:** [July 14, 2010, 2:32pm UTC](https://www.ruby-forum.com/t/search-area/191513/2 "2010-07-14T14:32:04Z")

</div>

have you tried Intervenant.where(“code like ? or id like ?”,  
params[:search], params[:search]).

consider using searchlogic gem.
