1
class SessionsController < ApplicationController
def new
@title = "Sign in"
end
def create
user = User.authenticate(params[:session][:email],
params[:session][:password])
if user.nil?
flash[:error] = "Invalid email/password combination."
@title = "Sign in"
render 'new'
else
# Sign the user in and redirect to the user's show page.
end
end
def destroy
end
end
當前正在開發一個項目並且有一個未定義的NoMethodErorr。完成徹底的研究,仍然無法找到任何東西。我所做的是,在創建操作中,參數需要參數驗證所需的參數。我創建了以下方法User.authenticatte。但是,當我在我的本地主機運行這個我得到以下錯誤。可能是什麼問題?SessionsController中的NoMethodError#create
NoMethodError in SessionsController#create
undefined method `authenticate' for #<Class:0x4589eb0>
你的用戶模型是什麼樣的? – Dogbert
是你的方法名'authenticatte'(你提到的問題)?如果是這樣,那麼你必須在創建操作中調用相同的方法。理想情況下,它應該被稱爲'authenticate' –
我已經解決它現在感謝回覆我的帖子 – David