Forum: Ruby on Rails undefined method `[]' for nil:NilClass

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Craig W. (Guest)
on 2007-01-19 17:29
(Received via mailing list)
I have an interesting situation and I am wondering if I can trap just
this specific error...

undefined method `[]' for nil:NilClass

which comes the user is trying to access a controller method which
assumes session variables that no longer exist because the session has
timed out.

I would rather bounce them to a static web page than toss the
application error in this case. Is this possible?

Craig W. <removed_email_address@domain.invalid>
Philip H. (Guest)
on 2007-09-26 00:30
(Received via mailing list)
> application error in this case. Is this possible?

   #access the session that errors out
   redirect_to '/somewheresafe'

Or test it using nil? before calling [] on it...
This topic is locked and can not be replied to.