I am having trouble with this bit of code
if request.get?
session[:user_id] = nil
@user = User.new
logger.error("get:#{@user.object_id}")
else
logger.error("post:#{@user.object_id}")
logged_in_user = @user.try_to_login
if logged_in_user
session[:user] = logged_in_user.id
redirect_to(:action => "index")
else
flash[:notice] = "Invalid user/password combo"
end
For some reason, when posting back the object_id of the @user variable
is 4 but when the get? is executed, the object_id is 28208630.
The error message is
NoMethodError (You have a nil object when you didn’t expect it!
The error occured while evaluating nil.try_to_login):
This happens if i enter a user name and password or leave them both
blank, and yes there is a method called try_to_login. Im trying to learn
rails and the code is exactly as is written in the book. Could something
have changed in rails since the book was published?