title: ruby-on-rails check if query result is empty (Model.find)
body: <p>i´m using ruby on rails and trying to check if a query is returning a value or not.</p>
  
  <p>This is the query:</p>
  
  <pre><code>@search = Customer.find_by_name($login_name)
  </code></pre>
  
  <p>If the query finds a result, everything is fine, but how can i react on empty results?</p>
  
  <p>I tried:</p>
  
  <pre><code>if @search.empty?
    flash[:notice] = 'Username nicht bekannt'
    redirect_to :action =&gt; :login
  end
  </code></pre>
  
  <p>But i get an error:</p>
  
  <pre><code>undefined method `empty?' for nil:NilClass
  </code></pre>
  
  <p>Any Ideas what went wrong?</p>
  
  <p>Thank you!!!</p>