# Tackling Double Rendering

**URL:** <https://www.ruby-forum.com/t/tackling-double-rendering/129524>\
**Category:** Rails\
**Created:** [February 19, 2008, 8:53am UTC](https://www.ruby-forum.com/t/tackling-double-rendering/129524 "2008-02-19T08:53:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MohsinHijazee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e68b1a/32.png) [@MohsinHijazee](https://www.ruby-forum.com/u/MohsinHijazee)\
**Post date:** [February 19, 2008, 8:53am UTC](https://www.ruby-forum.com/t/tackling-double-rendering/129524/1 "2008-02-19T08:53:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MohsinHijazee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e68b1a/32.png) [@MohsinHijazee](https://www.ruby-forum.com/u/MohsinHijazee)\
**Post date:** [February 19, 2008, 9:08am UTC](https://www.ruby-forum.com/t/tackling-double-rendering/129524/2 "2008-02-19T09:08:32Z")

</div>

On Feb 18, 2008 11:52 PM, MohsinHijazee [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> 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?

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![MohsinHijazee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e68b1a/32.png) [@MohsinHijazee](https://www.ruby-forum.com/u/MohsinHijazee)\
**Post date:** [February 19, 2008, 9:24am UTC](https://www.ruby-forum.com/t/tackling-double-rendering/129524/3 "2008-02-19T09:24:30Z")

</div>

On Feb 19, 1:07 pm, “Rick O.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 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?

---

<div class="post-metadata">

**Author:** ![MohsinHijazee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e68b1a/32.png) [@MohsinHijazee](https://www.ruby-forum.com/u/MohsinHijazee)\
**Post date:** [February 19, 2008, 6:47pm UTC](https://www.ruby-forum.com/t/tackling-double-rendering/129524/4 "2008-02-19T18:47:31Z")

</div>

On 2/19/08, MohsinHijazee [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > ```
> > > format.json { render :json => json and return }
> > > 
> > > ```
> > > 
> > > 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?

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/](http://talklikeaduck.denhaven2.com/)
