Try
def is_logged_in? @logged_in_user = User.find(session[:user]) if session[:user] end
Try
def is_logged_in? @logged_in_user = User.find(session[:user]) if session[:user] end
Rick Lloyd wrote:
Try
def is_logged_in? @logged_in_user = User.find(session[:user]) if session[:user] end
On Apr 29, 10:15�am, Stephen Fagan <rails-mailing-l...@andreas-s.net>
Thanks Rick. It worked a treat and also opened up a couple of gaping holes aswell (which I've managed to rectify!)
Cheers
Stephen.
Just to followup if you're interested, .... the error msg from the op was due to the fact that the call to session[:user_id] returned nil, and thus calling find(nil) resulted in that error being raised. If you wanted to avoid such an error and just have the find call return nil if not found, one way is to just call find_by_id:
$ ./script/console
u = User.find(nil)
ActiveRecord::RecordNotFound: Couldn't find User without an ID from /usr/lib/ruby/... ...
u = User.find_by_id(nil)
=> nil
Jeff