# Rendering partial and js together

**URL:** <https://www.ruby-forum.com/t/rendering-partial-and-js-together/164226>\
**Category:** Rails\
**Created:** [March 30, 2009, 6:21am UTC](https://www.ruby-forum.com/t/rendering-partial-and-js-together/164226 "2009-03-30T06:21:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tkbeili](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@tkbeili](https://www.ruby-forum.com/u/tkbeili)\
**Post date:** [March 30, 2009, 6:21am UTC](https://www.ruby-forum.com/t/rendering-partial-and-js-together/164226/1 "2009-03-30T06: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  
respond\_to do|wants|  
wants.js do  
render :update do |page|  
page \<\< “jq(’#message\_title, #message\_body’).val(’’);”  
page \<\< “tb\_remove()”  
end  
end  
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:** ![tkbeili](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@tkbeili](https://www.ruby-forum.com/u/tkbeili)\
**Post date:** [March 30, 2009, 5:03pm UTC](https://www.ruby-forum.com/t/rendering-partial-and-js-together/164226/2 "2009-03-30T17:03:37Z")

</div>

Hi Tam,

On Mon, 2009-03-30 at 06:21 +0200, Tam K. wrote:

> ```
> end
> 
> ```
> 
> 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|  
page \<\< “jq(’#message\_title, #message\_body’).val(’’);”  
page \<\< “tb\_remove()”  
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 F.'s ‘RJS Templates’ PDF available at  
O’Reilly. Very good expenditure of $10.

HTH,  
Bill
