Rails 4.2.6 authenticate error method

0

I'm trying to use the authenticate method and 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 the rails console also and it returns the same error. When trying to list the object's methods by the console it returns an entire disorganized list "user.methods?" I can not find my error.

    
asked by anonymous 03.11.2016 / 01:01

1 answer

1

The authenticate method exists in the ActiveModel :: SecurePassword module and must be included in your model, via 'has_secure_password'.

class User < ActiveRecord::Base
  has_secure_password
end
    
03.11.2016 / 11:22