Reputation: 1
I'm following the Michael Hartl tutorial and I got stuck in chapter 9.
I need this function to work:
def signed_in? !current_user end
but this function always return false even when I'm logged. I'm sorry for this simple question, but I'm a begginer and also spend a long time trying figure it out. I'm using ruby 1.8.7 and rails 2.3.8
thanks in advanced!
Upvotes: 0
Views: 793
Reputation: 45
You have to add a .nil? to current_user like this:
def signed_in?
!current_user.nil?
end
Upvotes: 1
Reputation: 3646
I had a similar issue and decided to work backwards.
1) def signed_in?
!current_user.nil?
end
. So I looked for the declaration & definition of current_user associated with a sign-in
2) Here: def sign_in(user)
cookies.permanent.signed[:remember_token] = [user.id, user.salt]
self.current_user = user
end
. For me, token was misspelled and that fixed it.
Upvotes: 0
Reputation: 14716
I suspect the code should read
def signed_in?
current_user
end
Putting a !
in front of the call to current_user
can be read as "return true if it is NOT the current_user".
Your code inside of SessionsHelper
has a typo. The :remember_token
cookie is not getting saved off in the sign_in
method. It should read:
def sign_in(user)
user.remember_me!
cookies[:remember_token] = { :value => user.remember_token,
:expires => 20.years.from_now.utc }
self.current_user = user
end
Not :remember_toker
.
Upvotes: 1