I want to create a search form that appears in the header of my application (like the search in Stackoverflow).
T do this, I thought that I would put it into the layout for application.html.erb
But then what do I use as a route and action in the controller?
I want to pass the parameter to search through several ActiveRecords, probably using searchlogic.
Thanks.
This is very simple, may index with texticle later:
Here is my searches_controller.rb
1 class SearchesController < App开发者_开发问答licationController
2
3 def search
4
5 @contacts_search = Contact.search(:first_name_like => params[:search])
6
7
8
9 end
10 end
You should use a SearchController. I use ThinkingSphinx and it works fine, so no code to help there, but using a SearchController will allow you to route that way quite easily.
<% form_tag search_search_path, :method => :get do %>
<p id="search_header">
<%= text_field_tag 'q', params[:q], {:size => 40} %>
<%= submit_tag 'Search for Shops', :name => nil %>
</p>
<% end %>
Something like this. I called my search method search
in the Search
controller... that's why the double search in the route.
精彩评论