# Double render/redirect philosophy

**URL:** <https://www.ruby-forum.com/t/double-render-redirect-philosophy/183133>\
**Category:** Rails\
**Created:** [February 8, 2010, 8:04pm UTC](https://www.ruby-forum.com/t/double-render-redirect-philosophy/183133 "2010-02-08T20:04:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [February 8, 2010, 8:04pm UTC](https://www.ruby-forum.com/t/double-render-redirect-philosophy/183133/1 "2010-02-08T20:04:08Z")

</div>

Ok, I think I understand why RoR will flag an attempt double render in  
an action.

What I don’t understand is the philosophy of render and redirect\_to.

Specifically, why isn’t a return implicit in both those methods?

Or, I guess, more to the point … what are the advantages of writing  
code in the action after a render/redirect\_to?

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [February 8, 2010, 8:09pm UTC](https://www.ruby-forum.com/t/double-render-redirect-philosophy/183133/2 "2010-02-08T20:09:31Z")

</div>

There isn’t much point in writing code after a render/redirect in a  
controller method, and it’s safe to say it’s a best practice not to. I  
think the main reason render/redirect work the way they do is to make  
it easier to use those methods in before/after\_filters.

For what it’s worth, Merb’s render/redirect implementation is what you  
suggest here.

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [February 8, 2010, 8:27pm UTC](https://www.ruby-forum.com/t/double-render-redirect-philosophy/183133/3 "2010-02-08T20:27:41Z")

</div>

On 9/2/2010 3:04 AM, Ralph S. wrote:

> Ok, I think I understand why RoR will flag an attempt double render in  
> an action.
> 
> What I don’t understand is the philosophy of render and redirect\_to.
> 
> Specifically, why isn’t a return implicit in both those methods?
> 
> Or, I guess, more to the point … what are the advantages of writing  
> code in the action after a render/redirect\_to?

I’m not sure how Rails works, but in a C++ HTTP server that we did, we  
could do something like write the response to the browser and then do  
the remaining house-keeping tasks. For example, it would be perfectly  
fine to update the logs, perform some other calculation, etc. that does  
not affect the output (since it’s been sent off already) but is  
something that the system could use.

In another system, we did something like receive a request by HTTP POST,  
check the parameters and acknowledge the receipt of the request to the  
client as the response. Thereafter, we needed to process the request  
(which took quite a while) and then we would POST the results to a URL  
on the client’s side.

I think both these cases would be things that don’t need to be put into  
an after\_filter and would benefit from writing code in the action after  
a render (assuming Rails works/ allows one to work this way).

Cheers,  
Mohit.  
9/2/2010 | 3:26 AM.

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [February 9, 2010, 4:59pm UTC](https://www.ruby-forum.com/t/double-render-redirect-philosophy/183133/4 "2010-02-09T16:59:19Z")

</div>

On Feb 8, 2:04 pm, Ralph S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Ok, I think I understand why RoR will flag an attempt double render in  
> an action.
> 
> What I don’t understand is the philosophy of render and redirect\_to.
> 
> Specifically, why isn’t a return implicit in both those methods?

Unless I’ve completely missed something, there isn’t a straightforward  
way to issue a nonlocal return in Ruby - which you’d need in order to  
make calling ‘render’ return from the controller action. One could, of  
course, hack up something involving raise/rescue, but that’s going to  
be messy.

–Matt J.
