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