# Rendering partial and js together

**URL:** <https://discuss.rubyonrails.org/t/rendering-partial-and-js-together/41005>\
**Category:** rubyonrails-talk\
**Created:** [March 30, 2009, 4:21am UTC](https://discuss.rubyonrails.org/t/rendering-partial-and-js-together/41005 "2009-03-30T04:21:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [March 30, 2009, 4:21am UTC](https://discuss.rubyonrails.org/t/rendering-partial-and-js-together/41005/1 "2009-03-30T04:21:40Z")

</div>

Hello,

I have a form on my page that is popup-like but actually part of the page. it works fine as I used in other page. In order to close it after submission. I do something like &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;respond\_to do|wants| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wants.js do &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;render :update do |page| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;page \<\< "jq('#message\_title, #message\_body').val('');" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;page \<\< "tb\_remove()" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

As requirements change I was to update another DIV with listing so I would like to do something like render :partial =\> 'client\_listing', :locals =\> {:listing\_clients =\> @listing\_clients}

I need to do both together but I can as you can only render once per method with Rails: actionController::DoubleRenderError in SmsController#add\_client

Can only render or redirect once per action

Any ideas how I can approach this issue as I need to perform both actions?

Thanks,

Tam

---

<div class="post-metadata">

**Author:** ![Bill\_Walton1](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Bill\_Walton1](https://discuss.rubyonrails.org/u/Bill_Walton1)\
**Post date:** [March 30, 2009, 3:03pm UTC](https://discuss.rubyonrails.org/t/rendering-partial-and-js-together/41005/2 "2009-03-30T15:03:26Z")

</div>

Hi Tam,

> Hello,
> 
> I have a form on my page that is popup-like but actually part of the page. it works fine as I used in other page. In order to close it after submission. I do something like &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;respond\_to do|wants| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wants.js do &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;render :update do |page| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;page \<\< "jq('#message\_title, #message\_body').val('');" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;page \<\< "tb\_remove()" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end
> 
> As requirements change I was to update another DIV with listing so I would like to do something like render :partial =\> 'client\_listing', :locals =\> {:listing\_clients =\> @listing\_clients}
> 
> I need to do both together but I can as you can only render once per method with Rails: actionController::DoubleRenderError in SmsController#add\_client
> 
> Can only render or redirect once per action
> 
> Any ideas how I can approach this issue as I need to perform both actions?

If I understand you correctly, you can accomplish what you're trying to do by using the RJS replace\_html method within the render :update. Assuming there's an element already on the page within which you'd like to render the partial above...

render :update do |page| &nbsp;&nbsp;page \<\< "jq('#message\_title, #message\_body').val('');" &nbsp;&nbsp;page \<\< "tb\_remove()" &nbsp;&nbsp;page.replace\_html 'existing\_element', :partial =\> 'client\_listing', :locals =\> {:listing\_clients =\> @listing\_clients} end

The 'replace\_html' method will replace the html content inside 'existing\_element'.

There's also a straight 'replace' method which replaces the html content AND the enclosing element.

I highly recommend Cody Fauser's 'RJS Templates' PDF available at O'Reilly. Very good expenditure of $10.

HTH, Bill
