Search area


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 =[:search])
render :index

In my model:
params.keys.inject(scoped({})) do |found, k|
params[k].blank? ? found : found.send(:"#{k}", params[k])
scope :by_code, lambda {|name| where(“intervenants.code LIKE ?”,
scope :by_id, lambda {|name| where(“ LIKE ?”,

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 !

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

consider using searchlogic gem.