How can I forward to different pages for different account


#1

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 …


#2

On 25 Mar., 02:23, Zhao Yi removed_email_address@domain.invalid 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 K.
http://twitter.com/rubyguy


#3

On Tue, Mar 24, 2009 at 8:23 PM, Zhao Yi
removed_email_address@domain.invalid 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 D.
http://destiney.com/


#4

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