Probably something like
if session[''user''].nil?
redirect_to whatever
end
You would probably want to make this into a filter, too
-----Original Message-----
From: rails-bounces@lists.rubyonrails.org
[mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Jasbur
Sent: Wednesday, June 07, 2006 12:04 PM
To: rails@lists.rubyonrails.org
Subject: [Rails] Redirect if session is nil
How exactly do i redirect a user if they''re not logged in?
I have a cookie being written to the @session variable on login and I
can pull info from it. For instance
"@session[''user''].login" pulls their
username just fine. But if they type in the url of the "welcome" page
without logging in I get "You have a nil object when you didn''t
expect
it!" which I would expect.
Instead of this nasty error message, how would I redirect them to the
login page?
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
Rails mailing list
Rails@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails