Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First off, a few tweaks to your Ruby.</p> <pre><code>def search_page? true end </code></pre> <p>You don't need the semi-colon or the <code>return</code> (whatever the last line will be the return value of your method).</p> <p>Second, all helpers get loaded when your app is initialised. You can change this behaviour, but it's probably not worth it.</p> <p>As for the rest, let's say you have a partial called <code>_search_form.html.erb</code>. Create a nice helper method (say, in search_helper.rb)</p> <pre><code>def search_form render(:partial =&gt; 'search/search_helper') unless @search_page end </code></pre> <p>Use this to call the search form from your layout file. From then, you have some choices.</p> <p>You can either create a <code>before_filter</code> in your controller:</p> <pre><code>before_filter :set_search_page ...your actions here... private def set_search_page @search_page = true end </code></pre> <p>Or set the variable in your action:</p> <pre><code>def some_action @search_page = true end </code></pre> <p>I'd say though that this is really a view issue, rather than something you want to be doing in your controllers. I'd create a helper method like this (again, in <code>search_helper.rb</code>).</p> <pre><code>def search_page @search_page = true end </code></pre> <p>And then in the top of your view for that page, I'd use something like this:</p> <pre><code>&lt;% search_page %&gt; </code></pre> <p>(Note that it's <code>&lt;%</code> and not <code>&lt;%=</code> -- there's no output.)</p> <p>The advantage here is you keep needless instance variables free from your controller.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload