What is the best way to update more that 1 div in AJAX call

Hello,

I want to update more than 1 div inside the page with 1 AJAX call.
I noticed you can only render 1 at a time in Rails methods and also you
can only set 1 update: inside form_remote_for.

What is the best way to update more than once?

I was thinking to deliver it back in hidden field and then use
JavaScript to upload it in the other DIV. I’m guessing though there must
be better way to do this in rails

Any ideas?

Thanks,

Tam

I want to update more than 1 div inside the page with 1 AJAX call.
I noticed you can only render 1 at a time in Rails methods and also
you
can only set 1 update: inside form_remote_for.

What is the best way to update more than once?

Look into update_page and the methods you can put inside it’s block
(particular replace_html). In the form_remote_for/link_to_remote case
you don’t specify the :update parameter. Let the RJS that gets
returned do your bidding. You’re still only rendering one thing, but
that render is a bunch of JS that does what you want…

update_page(&block)

Yields a JavaScriptGenerator and returns the generated JavaScript
code. Use this to update multiple elements on a page in an Ajax
response. See JavaScriptGenerator for more information.

Example:

update_page do |page|
page.hide ‘spinner’
# and other things…
end

Hi
In controller suppose action is replace_this then create a file
replace_this.rjs in the same folder
Now in action write
render :action => 'replace_this.rjs"

And open replace_this.rjs
page[:div1].replace_html :partial=>“partial_here”}

  Above you can use :inline, etc instead of :partial

Look
http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html

Sijo

Thanks a lot Philip and Sijo, you solutions are very helpful I will be
using RJS for that