
undefined method `authenticate’ forって出たら
undefined method `authenticate' for # Did you mean? authenticatable_salt
上記のようなエラーが出た。railsをweb api化しててユーザーログイン処理をapi化しようとした時に出たエラー。眠いので細かい説明省くけどようは下記のような感じにすればok
def login
user = User.find_by(email: params[:email].downcase)
if user && user.encrypted_password == BCrypt::Engine.hash_secret(params[:password], user.encrypted_password)
render json: {token: user.token}
else
render json: {token: 'faild'}
end
end