title: undefined method `authenticate' for #<ActiveRecord::Relation []>
body: <p>I have created a method "attempt_login" as given below:</p>
  
  <pre><code>def attempt_login
    if params[:username].present? &amp;&amp; params[:password].present?
        found_user= AdminUser.where(:username=&gt; params[:username].first)
    if found_user
      authorized_user= found_user.authenticate(params[:password])
    end
  end
  if authorized_user
    flash[:notice]="You are now logged in."
    redirect_to(:action=&gt;'menu')
  else
     flash[:notice]="Invalid username/password combination."
     redirect_to(:action=&gt;'login')
    end
  end
  </code></pre>
  
  <p>I am getting an error like this:</p>
  
  <pre><code> ←[1m←[35mAdminUser Load (1.0ms)←[0m  SELECT `admin_users`.* FROM `admin_users`
    WHERE `admin_users`.`username` = 'u'
  Completed 500 Internal Server Error in 18ms
  
  NoMethodError (undefined method `authenticate' for #&lt;ActiveRecord::Relation []&gt;)
  :
    app/controllers/access_controller.rb:13:in `attempt_login'
  </code></pre>
  
  <p>It is working from rails console, but not from rails server.
   please tell me the solution, i am waiting for your reply.</p>