title: Ruby on Rails search form parameter initialisation at server startup
body: <p>Inspired by the tutorial from Michael Hartl, I developped a business rules assessment application.
  When my user logs in, he lands on the home page, defined in routes.rb as</p>
  
  <pre><code> root to: "dashboards#home"
  </code></pre>
  
  <p>The home page actually displays a dashboard of top 10 failling business rules, and 10 most recently updated ones. It's a start ... and it works fine.</p>
  
  <p>Then I added a simple search as per RailsCast #37, to help filtering quickly some particular business rule. During the development, all worked correctly, but when I restart the rails server, I get this error message about the 'search' parameter:</p>
  
  <pre><code>undefined method `empty?' for nil:NilClass
  </code></pre>
  
  <p>when assessing the 'search' parameter, it just does not exist yet !</p>
  
  <p>Here is the code: </p>
  
  <ol>
  <li>The home page is defined in the dashboards folder, and pushed by the
  dashboards controller. </li>
  <li>The dashboard controller instanciates the @business_rules_search relying on the search function</li>
  <li>the search function is implemented in the model.</li>
  </ol>
  
  <p>The home page extract:</p>
  
  <pre><code>      &lt;div class="span4"&gt;
        &lt;h4&gt;Search for Business Rules&lt;/h4&gt;
        &lt;%= form_tag :root, :method =&gt; 'get' do %&gt;
          &lt;p&gt;
            &lt;%= text_field_tag :search, params[:search] %&gt;
            &lt;%= submit_tag "Search", :name =&gt; nil %&gt;
          &lt;/p&gt;
        &lt;% end %&gt;
        &lt;table class="table table-striped"&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;/th&gt;
            &lt;th&gt;Code&lt;/th&gt;
            &lt;th&gt;Name&lt;/th&gt;
            &lt;th&gt;Status&lt;/th&gt;
          &lt;/tr&gt;
  
        &lt;% @business_rules_search.each do |business_rule| %&gt;
          &lt;tr&gt;
            &lt;td&gt;&lt;%= image_tag(index_audit_tag_for(business_rule), :alt =&gt; "Quality hit") %&gt;&lt;/td&gt;
            &lt;td class="col_narrow"&gt;&lt;%= link_to business_rule.code, business_rule %&gt;&lt;/td&gt;
            &lt;td&gt;&lt;%= business_rule.name %&gt;&lt;/td&gt;
            &lt;td&gt;&lt;%= business_rule.status.name %&gt;&lt;/td&gt;
          &lt;/tr&gt;
        &lt;% end %&gt;
        &lt;/table&gt;
  
        &lt;/div&gt;
  </code></pre>
  
  <p>The dashboard controller:</p>
  
  <pre><code>class DashboardsController &lt; ApplicationController
  
    def home
      @business_rules_index=BusinessRule.pgnd(current_playground).order("score ASC").limit(10)
      @business_rules_updated=BusinessRule.pgnd(current_playground).order("updated_at DESC").limit(10)
      @business_rules_search=BusinessRule.pgnd(current_playground).search(params[:search]).limit(10)
    end
  
  end
  </code></pre>
  
  <p>The search function:</p>
  
  <pre><code>def self.search(search)
    if not search.empty?
      where('name like ?', "%#{search}%")
    else
      where('1=1')
    end
  end
  </code></pre>
  
  <p>I hope you can help me understand why this parameter usage does not work after server restart ?</p>
  
  <p>Thanks for your help,</p>
  
  <p>Best regards,</p>
  
  <p>Fred</p>