# How can I forward to different pages for different account

**URL:** <https://www.ruby-forum.com/t/how-can-i-forward-to-different-pages-for-different-account/163806>\
**Category:** Rails\
**Created:** [March 25, 2009, 2:23am UTC](https://www.ruby-forum.com/t/how-can-i-forward-to-different-pages-for-different-account/163806 "2009-03-25T02:23:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [March 25, 2009, 2:23am UTC](https://www.ruby-forum.com/t/how-can-i-forward-to-different-pages-for-different-account/163806/1 "2009-03-25T02:23:36Z")

</div>

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 …  
…

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [March 25, 2009, 7:57am UTC](https://www.ruby-forum.com/t/how-can-i-forward-to-different-pages-for-different-account/163806/2 "2009-03-25T07:57:50Z")

</div>

On 25 Mar., 02:23, Zhao Yi [removed\_email\_address@domain.invalid](mailto: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](http://twitter.com/rubyguy)

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [March 25, 2009, 4:33pm UTC](https://www.ruby-forum.com/t/how-can-i-forward-to-different-pages-for-different-account/163806/3 "2009-03-25T16:33:11Z")

</div>

On Tue, Mar 24, 2009 at 8:23 PM, Zhao Yi  
[removed\_email\_address@domain.invalid](mailto: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/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [March 28, 2009, 4:32am UTC](https://www.ruby-forum.com/t/how-can-i-forward-to-different-pages-for-different-account/163806/4 "2009-03-28T04:32:00Z")

</div>

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
