Ruby on Rails Sunday, July 31, 2011

I'm going to use these methods in my app instead of the current_user
method in the book:

#getter method:
def current_user
@current_user
end

#setter method:
def current_user=(user)
@current_user = user
end


def update_current_user
user = current_user #calls getter method
return user if user

cookie_arr = cookies.signed[:remember_token]

if cookie_arr
self.current_user = User.authenticate_with_salt(*cookie_arr)
#calls setter method

return current_user #calls getter method
else
return nil
end

end


Any time the book calls current_user, I plan on calling
update_current_user
instead.

--
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.

No comments:

Post a Comment