Thursday, May 5, 2011

[Rails] Re: Why returns nil?

>
> # since 'user = find_by_email(email)' was the last evaluated expression
>

Wrong. In case user doesn't match password then last evaluated statement
was

if user.has_password?(submitted_password)

which is a 'if modifier' for 'return user' statement; and it returned
nil. See from irb session:

ruby-1.9.2-p0 > true if false
=> nil
ruby-1.9.2-p0 > true if true
=> true

In case 'if modifier' evaluates to false it will return nil - which is
exactly your case.

----
http://blog.eugen.co

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate