Ruby on rails problem - stuck with find_by()

Associate
Joined
30 Dec 2005
Posts
415
Hi all,

I've been tearing my hair out the past few days due to a simple problem I can't work out. Unfortunately I can't find any decent RoR forums so it's a bit of a long shot posting on here, but I'm hoping that someone can help!

I have the following code..


Code:
def self.authenticate(user_info)
  u = find_by_email(user_info[:email])
  RAILS_DEFAULT_LOGGER.error(debug(u))
  RAILS_DEFAULT_LOGGER.error('Password: '+u.password);
end

I get the following error message.. can't convert nil into String

If I look at the log it's printed the entire object (debug(u))..

Code:
ruby/object:User
attributes:
  salt: "123"
  id: "1"
  password: "84fsd0fsj30j0jf3j0f0fsd80ssaa030j8e030j3"

But it hasn't printed the u.password..

Code:
TypeError (can't convert nil into String)

Can someone help me as to why u.password doesn't work?

Thanks in advance,
Richard
 
I don't do RoR, only plain ruby, but try

PHP:
RAILS_DEFAULT_LOGGER.error('Password: '+u.password.to_s)

i.e. i guess password is of non-string type, but probably has a to_s method?
 
Just managed to fix this.. I changed the field name in the database from 'password' to 'pass'. I guess the name was conflicting with my authentication code!
 
Back
Top Bottom