Hello everyone,
I’m learning Rails through the railtutorial.org book. I’m following very closely every detail taught in the book. However, there’s something that I don’t seem to find a solution. I have the following snippet of code:
def authenticate(email, submitted_password)
user = find_by_email(email)
#user = where(:email => email).first
(user && user.has_password?(submitted_password)) ? user : nil
end
def authenticate_with_salt(id, cookie_salt)
user = find_by_id(id)
#user = where(:id => id)
(user && user.salt == cookie_salt) ? user : nil
end
end
in the authenticate method, the find_by_id(id) call is returning nil. Going to the console, the function is not available to me whenever I call it. The funny thing is that it does not throw an exception (it’s heavily using meta-programming), so the method is generated on the fly, I guess. The thing is: the method is being called, but always returns nil. Does anyone know why is this happening? I had to replace the code by user = where(:email => email).first, for example. It works flawlessly. Can it be something related to the Ruby version I’m using?
$ ruby -v ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.5.0]
$ rails -v Rails 3.0.9
$ gem list activerecord activerecord (3.0.9, 3.0.1) I appreciate any help …
Thanks,
-fred