Tackling Double Rendering

199 views
Skip to first unread message

MohsinHijazee

unread,
Feb 19, 2008, 2:52:55 AM2/19/08
to Ruby on Rails: Talk
Hi!
I am calling a method like this:

def index()

json = super.get_customers()

respond_to do |format|
format.json { render :json => json and return }
end
end

But the problem is that the underlying method get_customers might have
called a render :text => 'Invalide Parameters or whatever' earlier and
the later code under the respond_to gives double render error. Is
there any way to discard the results of the previous rendering and
start at a clean slate?

Regards,
Moshin

Rick Olson

unread,
Feb 19, 2008, 3:07:57 AM2/19/08
to rubyonra...@googlegroups.com

return from the action early.

return if performed?

--
Rick Olson
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com

MohsinHijazee

unread,
Feb 19, 2008, 3:23:59 AM2/19/08
to Ruby on Rails: Talk


On Feb 19, 1:07 pm, "Rick Olson" <technowee...@gmail.com> wrote:
> On Feb 18, 2008 11:52 PM, MohsinHijazee <mohsinhija...@gmail.com> wrote:
>
>
>
>
>
> > Hi!
> > I am calling a method like this:
>
> > def index()
>
> > json = super.get_customers()
>
> > respond_to do |format|
> > format.json { render :json => json and return }
> > end
> > end
>
> > But the problem is that the underlying method get_customers might have
> > called a render :text => 'Invalide Parameters or whatever' earlier and
> > the later code under the respond_to gives double render error. Is
> > there any way to discard the results of the previous rendering and
> > start at a clean slate?
>
> > Regards,
> > Moshin
>
> return from the action early.
>
> return if performed?
>
And what if we need to render in any case? By wiping out the previous
renders?
> --
> Rick Olsonhttp://lighthouseapp.comhttp://weblog.techno-weenie.nethttp://mephistoblog.com

Rick DeNatale

unread,
Feb 19, 2008, 12:35:49 PM2/19/08
to rubyonra...@googlegroups.com

Well you should redesign so as not to have to do that, but there is an
undocumented method erase_render_results in ActionController::Base

By the way that super.get_customers is suspicious. Ruby doesn't let
you call super with a message name other than the current one.

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

Reply all
Reply to author
Forward
0 new messages