has_secure_password를 사용하여 샘플 로그인을하려고합니다. 이 같은로그인 레일 3 "SessionsController #에서 NameError 생성"
sessions_controller.rb
라인 8 개 모습을이 파일에서
undefined local variable or method `password_digest' for #<User:0x23129a0>
app/controllers/sessions_controller.rb:8:in `create'
: 보석 파일이 추가되지만이 오류가 계속
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
안녕하세요. 단지베이스를 커버하기 위해 1) 사용자 모델에 user_rb 파일에'has_secure_password'를 추가하고 2) 마이 그 레이션을 통해 사용자 모델에 기인 한'password_digest'를 추가 했습니까? – jvillian
이것은 다음과 같습니다. http://stackoverflow.com/questions/7759025/cant-use-has-secure-password-password-digest-error – bento
"사용자 모델에 할당되었습니다"를 어떻게 추가합니까? 내 모델 사용자는 다음과 같습니다 : class User
Overduka