Rails 4.2.6 error authenticate method

Asked

Viewed 37 times

0

I am trying to use the authenticate method and the Rails returns Nomethoderror: Undefined method `authenticate' for #.

My controller: class Sessionscontroller < Applicationcontroller #include Sessionshelper

def login
    render 'admin/login'
end

def create
    user = User.where(:email => params[:session][:email].downcase).first

    if user && user.authenticate(params[:session][:password])
        #log_in user
        redirect_to :controller => 'admin', :action => 'index'
    else
        flash[:danger] = "Email ou senha inválido"
        render 'login'
    end
end

end

I tried to do also by the Rails console and returns the same error. When trying to list the object methods by the console it returns an entire unorganized list "user.methods?" I can’t find my mistake.

  • Detail have installed bcrypt (3.1.11) bcrypt-ruby (3.1.5)

1 answer

1


The authenticate method exists in the Activemodel::Securepassword module and needs to be included in your model, via has_secure_password'.

class User < ActiveRecord::Base
  has_secure_password
end

Browser other questions tagged

You are not signed in. Login or sign up in order to post.