title: Rails 3 , Simple search form problem
body: <p>Code in my product model (product.rb):</p>
  
  <pre><code>   def self.search(search)
      if search
       find(:all)
      else
       find(:all)
      end
    end
  </code></pre>
  
  <p>Code in my search controller (search_controller.rb):</p>
  
  <pre><code>  def index
      @products = Product.search("Apple")
    end
  </code></pre>
  
  <p>Code in my view (index.html.erb):</p>
  
  <pre><code>&lt;h1&gt;Products&lt;/h1&gt;
  
  &lt;% form_tag client_search_path , :method =&gt; :get do %&gt;
    &lt;p&gt;
      &lt;%= search_field_tag :term, params[:term], :class=&gt; "auto_search_complete"%&gt;
      &lt;%= submit_tag "Search", :name =&gt; nil, :class =&gt; 'button', :id =&gt; "search_bn" %&gt;
    &lt;/p&gt;
  &lt;% end %&gt;
  
  &lt;table border="1px"&gt;
    &lt;tr&gt;
      &lt;th&gt;Name&lt;/th&gt;
      &lt;th&gt;Brand&lt;/th&gt;
      &lt;th&gt;Quantity available&lt;/th&gt;
      &lt;th&gt;Category&lt;/th&gt;
      &lt;th&gt;Shopcenter name&lt;/th&gt;
      &lt;th&gt;Shopcenter streetnumb&lt;/th&gt;
      &lt;th&gt;Shopcenter streetname&lt;/th&gt;
      &lt;th&gt;Shopcenter postal&lt;/th&gt;
      &lt;th&gt;Shopcenter province&lt;/th&gt;
    &lt;/tr&gt;
  
  &lt;% for product in @products%&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;%= product.name %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= product.brand %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= product.quantity_available %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= product.category %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= product.shopCenter_name %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= product.shopCenter_streetNumb %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= product.shopCenter_streetName %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= product.shopCenter_postal %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= product.shopCenter_province %&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;% end %&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>I load this all is good, but if I comment one of the line of codes in my model:</p>
  
  <pre><code>  def self.search(search)
      if search
       #find(:all)
      else
       find(:all)
      end
    end
  </code></pre>
  
  <p>I expect this to work also at least for the initial render, or when I submit an empty search term, but it's not. And changing the code to of the model to:</p>
  
  <pre><code>  def self.search(search)
      if search
       find_all_by_name(search)
      else
       find(:all)
      end
    end
  </code></pre>
  
  <p>Doesn't work it gives me an error that the view is working with a nil object, which is impossible because my database has entries.</p>
  
  <p>Can someone explain what is going on? I have the impression that both the conditions in my model are being executed. At least that's what 2 puts statement in each case showed me.
  Please advice.</p>