SessionsController中的NoMethodError #create

好的,我正在使用Rails 4th ed从Pragmatic Bookshelf文本Agile Webdevelopment学习R on R.

我在第212页,我收到此错误…. NoMethodError in SessionsController#createapp/controllers/sessions_controller.rb:7:in 'create'

我把胡子拉到这里,我花了好几天试图追踪它。 这是指向的创建代码……

 def create if user = User.authenticate(params[:name], params[:password]) session[:user_id] = user.id redirect_to admin_url else redirect_to login_url, :alert => "Invalid user/password combination" end end 

任何古鲁都能帮助吗?

听起来您需要在您的用户模型中使用以下内容(我的书上的第203页)。如果这不是问题,请提供您的用户模型。

 def User.authenticate(name, password) if user = find_by_name(name) if user.hashed_password == encrypt_password(password, user.salt) user end end end