Hi - Having a problem with one of my if/else statements... def back if @session redirect_to :action => ''list'' <-- List can only be accessed if you''re logged in. else redirect_to :action => ''reference'' <-- Reference can be accessed at any time end end Problem is the code only seems to go as far as the if and never enters the else... If you''re not logged in and click back it automatically sends you to the login page which I don''t want, I want it to redirect to the reference page. I have a feeling that it is something small I''m leaving out but none the less I can''t figure it out. Thanks Gearoid -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Um, why are you checking for session? Unless you''ve manually turned it off, a session will always exist for any connection. Even then, that''s not very good practice. You really should be doing something like: if session[:user] ... else ... end And as a side note, I don''t know what version of Rails you''re using but using the controller variables themselves (@session, @params, ...) is deprecated. You''re supposed to use the methods instead (session, params, ...). Jason On 6/21/07, Gearoid <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hi - > > Having a problem with one of my if/else statements... > > def back > if @session > redirect_to :action => ''list'' <-- List can only be accessed if you''re > logged in. > else > redirect_to :action => ''reference'' <-- Reference can be accessed at > any time > end > end > > Problem is the code only seems to go as far as the if and never enters > the else... If you''re not logged in and click back it automatically > sends you to the login page which I don''t want, I want it to redirect to > the reference page. > > I have a feeling that it is something small I''m leaving out but none the > less I can''t figure it out. > Thanks > Gearoid > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jason Roelofs wrote:> Um, why are you checking for session? Unless you''ve manually turned it > off, > a session will always exist for any connection. Even then, that''s not > very > good practice. You really should be doing something like: > > if session[:user] > ... > else > ... > end > > And as a side note, I don''t know what version of Rails you''re using but > using the controller variables themselves (@session, @params, ...) is > deprecated. You''re supposed to use the methods instead (session, params, > ...). > > JasonCheers Jason, I''m new to this and still finding my feet, thanks for the advice. Gearoid -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---