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!! -- Posted via http://www.ruby-forum.com/.
"because i become the error before it checks." What does that mean? This should work : if session[:user] do_something else do_somethingelse end -- Posted via http://www.ruby-forum.com/.
Try if @session[''user''].nil? redirect_to else redirect_to end -- Posted via http://www.ruby-forum.com/.
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 On 8/9/06, sabin <p_surber@yahoo.com> wrote:> 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!! > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
if is not a loop... loop is a loop, for, each, while, until are loops, but if not just wanted to clarify :) 2006/8/9, sabin <p_surber@yahoo.com>:> > 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!! > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Michael Siebert <info@siebert-wd.de> www.stellar-legends.de - Weltraum-Browsergame im Alpha-Stadium -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060810/c9c350c6/attachment.html