# Nested renders in the same call

**URL:** <https://www.ruby-forum.com/t/nested-renders-in-the-same-call/49838>\
**Category:** Rails\
**Created:** [December 9, 2005, 5:02am UTC](https://www.ruby-forum.com/t/nested-renders-in-the-same-call/49838 "2005-12-09T05:02:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [December 9, 2005, 5:02am UTC](https://www.ruby-forum.com/t/nested-renders-in-the-same-call/49838/1 "2005-12-09T05:02:11Z")

</div>

Hi there,

So I have discovered that I can’t do nested renders or redirects in the  
same rails call.

This is a shame as it prevents me from doing some things I was  
intending, such as being able to render editable components, e.g. you  
render a note component, but then you can edit it, or cancel it.

I can get round this by copying the show.rhtml for the note and giving  
it the name update.rhtml, and then having the output of the update  
action display the edited note, but I’m breaking the DRY principle here.

Also I’d like to be able to offer the user different options such as  
cancelling the edit, previewing etc. I guess I can hack my way out of  
this but it doesn’t seem very pretty.

Does anyone know why rails doesn’t support nested rendering.redirecting  
in the same call?

Many thanks in advance.

CHEERS\> SAM

---

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [December 9, 2005, 5:54am UTC](https://www.ruby-forum.com/t/nested-renders-in-the-same-call/49838/2 "2005-12-09T05:54:55Z")

</div>

On Dec 8, 2005, at 8:28 PM, Sam J. wrote:

> Hi there,
> 
> So I have discovered that I can’t do nested renders or redirects in  
> the  
> same rails call.

Are you sure about that? Many moons ago I used render\_component in  
my view files to call other controllers or actions that would, in  
turn, render their views. I imagine there’s a fancy  
render :component =\> {:controller =\> ‘/member’, :action =\> ‘signup’}  
type of thing now. Are you calling render\_component (or its  
equivalent) in the view file? Or is that not the kind of nesting you  
mean?

Duane J.  
(canadaduane)

---

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [December 9, 2005, 7:18pm UTC](https://www.ruby-forum.com/t/nested-renders-in-the-same-call/49838/3 "2005-12-09T19:18:34Z")

</div>

Hi Duane,

I’m pretty sure. I get this error:

ActionController::DoubleRenderError in Workspaces#update\_note

Can only render or redirect once per action

RAILS\_ROOT: D:/user/Code/ruby/prometheus/public/…/config/…  
Application Trace | Framework Trace | Full Trace

D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action\_controller/base.rb:579:in  
`render_with_no_layout' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action_controller/layout.rb:226:in`render\_without\_benchmark’  
D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action\_controller/benchmarking.rb:53:in  
`render' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action_controller/benchmarking.rb:53:in`measure’  
D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.0/lib/action\_controller/benchmarking.rb:53:in  
`render' #{RAILS_ROOT}/app/controllers/application.rb:51:in`componentize’  
#{RAILS\_ROOT}/app/controllers/workspaces\_controller.rb:97:in  
`update\_note’  
#{RAILS\_ROOT}/app/views/workspaces/show.rhtml:17

I have render\_component in my workspaces/show view, which then renders a  
workpaces/update\_note, as long as workspaces/update\_note doesn’t include  
an explicit render or redirect it works fine - if I render or redirect  
anything I get the above error.

CHEERS\> SAM

---

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [December 9, 2005, 7:22pm UTC](https://www.ruby-forum.com/t/nested-renders-in-the-same-call/49838/4 "2005-12-09T19:22:42Z")

</div>

Ah and I found an explanation:

[http://jamis.jamisbuck.org/articles/2005/07/08/rails-tip-of-the-day](http://jamis.jamisbuck.org/articles/2005/07/08/rails-tip-of-the-day)

CHEERS\> SAM

---

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [December 10, 2005, 11:20pm UTC](https://www.ruby-forum.com/t/nested-renders-in-the-same-call/49838/5 "2005-12-10T23:20:12Z")

</div>

On Dec 9, 2005, at 11:20 AM, Sam J. wrote:

> Ah and I found an explanation:
> 
> [http://jamis.jamisbuck.org/articles/2005/07/08/rails-tip-of-the-day](http://jamis.jamisbuck.org/articles/2005/07/08/rails-tip-of-the-day)
> 
> CHEERS\> SAM

Although not recommended for most situations, you can call  
erase\_render\_results, or simply set @performed\_render = false to  
clear the DoubleRenderError. Not sure what would happen if you do  
though…

Reminds me of Ren and Stimpy “Don’t press that RED BUTTON!! We don’t  
know what it will dooooo…”

Duane J.  
(canadaduane)
