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?
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?
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.
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)
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.