Checking session -newbie

hello!

i have a problem checking a session. i want to check if the session
exists, and then redirect somewhere, but in the if-loop, if the session
doesnt exist, i become an error

im trying to do something like:

if @session[‘user’] == nil
redirect_to …
else
redirect_to …
end

but as i said, the loop doesnt work, because i become the error before
it checks.
how can i check, if a session exist or not?

thanks!!

“because i become the error before it checks.”

What does that mean?

This should work :

if session[:user]
do_something
else
do_somethingelse
end

if is not a loop…
loop is a loop, for, each, while, until are loops, but if not
just wanted to clarify :slight_smile:

2006/8/9, sabin [email protected]:

redirect_to …

Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Michael S. [email protected]

www.stellar-legends.de - Weltraum-Browsergame im Alpha-Stadium

Try

if @session[‘user’].nil?
redirect_to
else
redirect_to
end

Try this:

if session && session[:user]

— [ we have a session ] —

redirect_to …
else

— [ perhaps we should redirect to login? ] —

redirect_to
end

Hope this helps,
Zack

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs