My web site has a login feature. What I want to do is to design different page for different account. But in an action, I couldn''t use redirect_to more than one time. I am looking for a way like this: if account == "admin" redirect_to ... else redirect_to ... ... -- 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 -~----------~----~----~----~------~----~------~--~---
rubyguy-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org
2009-Mar-25 06:57 UTC
Re: How can I forward to different pages for different account
On 25 Mar., 02:23, Zhao Yi <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> My web site has a login feature. What I want to do is to design > different page for different account. But in an action, I couldn''t use > redirect_to more than one time. I am looking for a way like this: > > if account == "admin" > redirect_to ... > else > redirect_to ... > ...That is because Rails only allows to do a single redirect or render per action. You can get around this by adding "and return" after the first redirect to prevent the rest of the code to get evaluated. if account == "admin" redirect_to some_page_path and return else redirect_to some_other_page_path end But do you really get an error when trying to do more than one redirect, when it''s inside an if/else statement? The "else" part should really not get evaluated if account == "admin"... -- Best regards, David Knorr http://twitter.com/rubyguy --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Greg Donald
2009-Mar-25 15:32 UTC
Re: How can I forward to different pages for different account
On Tue, Mar 24, 2009 at 8:23 PM, Zhao Yi <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> My web site has a login feature. What I want to do is to design > different page for different account. But in an action, I couldn''t use > redirect_to more than one time. I am looking for a way like this: > > if account == "admin" > redirect_to ...Add "return false" here.> else > redirect_to ...and here too. You have to make sure you only redirect once, returning false after the initial redirect will ensure this. -- Greg Donald http://destiney.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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hello. The problem with redirect_to is that it is counter-intuitive. It seems to say, when the code gets here I am going somewhere and never return. That is not the case. It is just like any other method call, you call it and it returns and then your code after the redirect_to keeps getting executed. That is the reason you should use return, as the rest of the posts suggest. Good luck. Pepe On Mar 24, 9:23 pm, Zhao Yi <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> My web site has a login feature. What I want to do is to design > different page for different account. But in an action, I couldn''t use > redirect_to more than one time. I am looking for a way like this: > > if account == "admin" > redirect_to ... > else > redirect_to ... > ... > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---