On Feb 21, 2012, at 1:34 PM, Roger Patrick wrote: > Hey I found out my problem, it was because I did not have the % symbol > in the last two search calls, all works fine now. > > Do you know how I would be able to make it as three separate search > boxes and buttons instead of all going in to one? > > All I know is how to search every column under one form but would like > to do it as three separate forms. Not like in the advance search by > railscast but three text fields with three submit buttons. > > Thanks > R. Patrick
Take a serious look at ransack. It's a very neat search gem, and it allows you to create specialized search fields just by naming those fields according to a dsl. So your controller would look like this: @q = ModelName.search(params[:q]) @model_names = @q.result(:distinct => true) No changes needed no matter what sort of hijinks you get up to in your view: <%= search_form_for @q do |f| %> <%= f.search_field :foo_cont, :class => 'search' %> (foo contains the search parameter) <%= f.search_field :bar_start, :class => 'search' %> (bar starts with the search parameter) <%= f.submit :name => nil, :value=> 'Search' %> <% end %> It contains the following predicates, which you just tail on to the name of the field you wish to search: eq not_eq matches does_not_match lt lteq gt gteq in not_in cont not_cont start not_start end not_end true false present blank null not_null And if that's not enough, you can create your own very directly. Walter > > -- > 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+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > -- 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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.