Undefined method `[]' for nil:NilClass


#1

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


#2

application error in this case. Is this possible?
Yes…

begin
#access the session that errors out
rescue
redirect_to ‘/somewheresafe’
end

Or test it using nil? before calling [] on it…