First of all, I'm new to RoR, so the answer may be obvious, in which case I apologize. I looked around and did not find anything useful.
I am trying to find a search form in the title of every web page in my application that will search for the names of all my buckets. Here is the relevant code:
In the application / views / layouts / _header.html.erb (in the navigation bar):
<% search_form_for @q do |f| %> <%= f.label :name_cont %> <%= f.text_field :name_cont %> <%= f.submit %> <% end %>
In application / controllers / buckets_controller.rb:
def index unless params[:q].blank? @q = Bucket.search(params[:q]) @buckets = @q.result.paginate(:page => params[:page]) else @buckets = Bucket.find(:all, :limit => 5).paginate(:page => params[:page]) end end
I understand that the last part is not so great: I try to do it, if I just get access to the bucket index page (not by searching), I show the last 5 buckets created. When I search for something in the form of a title, I go to the index page, but show only those buckets that fall into the search. (is it better to process it so that the search page is separate from my index page?)
I found this problem , which is pretty much identical, but I still donβt see how I handle @q , if every page goes to have a form on it - of course I donβt need to change each controller for every action?
Sorry in advance for any disappointment that I can call my love because you do it!
Eric
source share