Reputation: 3390
Ok, I'm learning R on R from the Pragmatic Bookshelf text Agile Webdevelopment with Rails 4th ed.
I'm at page 212 and I'm getting this error....NoMethodError in SessionsController#create
and app/controllers/sessions_controller.rb:7:in 'create'
I'm pulling my beard out over here, I've spent days trying to track this down. Here is the create code this is pointing to...
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
Can any Guru out there assist?
Upvotes: 1
Views: 1555
Reputation: 84180
Sounds like you need the following in your user model (page 203 on my book.) If that is not the issue, please provide your user model too.
def User.authenticate(name, password)
if user = find_by_name(name)
if user.hashed_password == encrypt_password(password, user.salt)
user
end
end
end
Upvotes: 1