Rendering partial and js together

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

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