title: ransack search form in header partial: No Ransack::Search object was provided to search_form_for
body: <p>First of all, I'm new to RoR, so the answer may be obvious, in which case I apologize.  I've looked around and haven't found anything that helps.</p>
  
  <p>I'm trying to have a search form at the header of every web page on my app that will search through the names of all my "buckets". Here is the relevant code:</p>
  
  <p>In app/views/layouts/_header.html.erb (within a nav bar):</p>
  
  <pre><code>&lt;% search_form_for @q do |f| %&gt;
    &lt;%= f.label :name_cont %&gt;
    &lt;%= f.text_field :name_cont %&gt;
    &lt;%= f.submit %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>In app/controllers/buckets_controller.rb:</p>
  
  <pre><code>def index
    unless params[:q].blank?
      @q = Bucket.search(params[:q])
      @buckets = @q.result.paginate(:page =&gt; params[:page])
    else
      @buckets = Bucket.find(:all, :limit =&gt; 5).paginate(:page =&gt; params[:page])
    end
  end
  </code></pre>
  
  <p>I understand the last part isn't that great: what I'm trying to do is if I'm just accessing the bucket index page (not by searching), i display the 5 most recently created buckets.  When I search for something in the header form, I access the index page but only show the buckets that hit the search. (would a better way to handle it to have a search page separate from my index page?)</p>
  
  <p>I found <a href="https://github.com/ernie/ransack/issues/3" rel="noreferrer">this issue</a> which is pretty much identical, but I still don't see how I handle <code>@q</code> if every page is going to have the form on it--surely I don't have to alter every controller's every action?</p>
  
  <p>Sorry in advance for any frustration my noobishness my cause you!</p>