# Developing code that can go multiple places

**URL:** <https://www.ruby-forum.com/t/developing-code-that-can-go-multiple-places/154457>\
**Category:** Rails\
**Created:** [November 29, 2008, 10:51pm UTC](https://www.ruby-forum.com/t/developing-code-that-can-go-multiple-places/154457 "2008-11-29T22:51:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsimone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@jsimone](https://www.ruby-forum.com/u/jsimone)\
**Post date:** [November 29, 2008, 10:51pm UTC](https://www.ruby-forum.com/t/developing-code-that-can-go-multiple-places/154457/1 "2008-11-29T22:51:18Z")

</div>

In my controller code, depending on the values in the database, I may  
want my user to go one of several places. But when I put more than one  
redirect in, it gives me the message:

Render and/or redirect were called multiple times in this action.

How do I do this?

---

<div class="post-metadata">

**Author:** ![jsimone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@jsimone](https://www.ruby-forum.com/u/jsimone)\
**Post date:** [November 29, 2008, 10:59pm UTC](https://www.ruby-forum.com/t/developing-code-that-can-go-multiple-places/154457/2 "2008-11-29T22:59:24Z")

</div>

On Nov 29, 2008, at 1:51 PM, Joe S. wrote:

> In my controller code, depending on the values in the database, I may  
> want my user to go one of several places. But when I put more than  
> one  
> redirect in, it gives me the message:
> 
> Render and/or redirect were called multiple times in this action.
> 
> ## How do I do this?

redirect\_to(some\_place) and return

Alternatively, store the desired destination URL and redirect once at  
the end of the method.

stored\_location = nil

# …

stored\_location = ‘fall\_down\_go\_boom\_url’ if some\_criteria

# …

redirect\_to stored\_location unless stored\_location.nil?

---

<div class="post-metadata">

**Author:** ![jsimone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@jsimone](https://www.ruby-forum.com/u/jsimone)\
**Post date:** [December 1, 2008, 3:35am UTC](https://www.ruby-forum.com/t/developing-code-that-can-go-multiple-places/154457/3 "2008-12-01T03:35:54Z")

</div>

Hi,

Maybe s.ross’s explanation is enough, but just in case, I had to deal  
with the same problem a while back and this might be useful…

redirect\_to doesn’t stop the rest of the code in your method/action  
from keeping executing so if you use it and then later on in your code  
there is another render/redirect\_to like, for example, as a default  
action after an if/select then there is your problem.

The solution is to use return right after you redirect\_to line:

redirect\_to  
return # here the code leaves the method/action

I hope this helps.

Pepe
