Forum: Ruby on Rails What is the best way to update more that 1 div in AJAX call

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
330edb8dc8bbc5a824984cf46e941b2f?d=identicon&s=25 Tam Kbe (tkbeili)
on 2009-04-01 07:19
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
2505b282d57c29be797dc35b245adb4c?d=identicon&s=25 Philip Hallstrom (Guest)
on 2009-04-01 07:24
(Received via mailing list)
>
> 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
661ae6e97d0e16c2af2aaf7d197e8387?d=identicon&s=25 Sijo k g (sijo)
on 2009-04-01 07:49
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/Help...

Sijo
330edb8dc8bbc5a824984cf46e941b2f?d=identicon&s=25 Tam Kbe (tkbeili)
on 2009-04-01 08:20
Thanks a lot Philip and Sijo, you solutions are very helpful I will be
using RJS for that
This topic is locked and can not be replied to.