我正在尝试使用 has_secure_password 进行示例登录。gem 文件已添加,但此错误仍然存在:
undefined local variable or method `password_digest' for #<User:0x23129a0>
app/controllers/sessions_controller.rb:8:in `create'
在这个文件中
sessions_controller.rb
第 8 行如下所示:
if user and user.authenticate(params[:password])
class SessionsController < ApplicationController
def new
end
def create
user = User.find_by_name(params[:name])
if user and user.authenticate(params[:password])
session[:user_id] = user.id
redirect_to admin_url , notice: "Login efetuado com sucesso."
else
flash[:notice] = 'Usuario ou senha errados'
redirect_to login_url
end
end
def destroy
session[:user_id] = nil
redirect_to login_url, notice: "Logout Efetuado com sucesso."
end
end