Forum: Ruby on Rails Strategies for updating multiple parts of the page with AJAX

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.
Tom L. (Guest)
on 2006-02-09 18:07
(Received via mailing list)
Hi all,

I have a layout that's evolving, but it looks like there will be several
divs.  I'm trying to keep everything AJAX-y and avoid full page reloads.
My
problem is, if I have the login box in a div, I'm going to want two
other
divs to effectively "refresh" themselves to get data from the server now
that there is a user logged in.

I'm trying to figure out how to accomplish this.  I know I can't do this
with my current layout, because each of these divs I want to refresh is
currently just a partial page template included on a page - nothing
AJAXy
about them.  If I want to have the ability to call on parts of the page
to
update themselves, any ideas how I can do that?  I'm not sure if there
are
rails helpers I can use, or if I should start looking into hand-coding
Javascript with the prototype library to come up with a way.

Also, if my mental model of how to do page updates is wrong, please
correct
me.

Thanks!
Tom
Kevin O. (Guest)
on 2006-02-09 18:34
Tom L. wrote:
> Hi all,
>
> I have a layout that's evolving, but it looks like there will be several
> divs.  I'm trying to keep everything AJAX-y and avoid full page reloads.
> My
> problem is, if I have the login box in a div, I'm going to want two
> other
> divs to effectively "refresh" themselves to get data from the server now
> that there is a user logged in.

Sounds like you might like RJS templates.  They are in edge rails but I
think there is a plugin for rails 1.0.

Alternatively, you could add some javascript to the :complete callback
in link_to_remote that will fire off another request.

link_to_remote 'link', :update=>'testdiv', :url=>{:action=>'action'},
:complete=> remote_function(:update=>'testdiv2',
:url=>{:action=>'action2'})

should do the trick.

_Kevin
Roberto S. (Guest)
on 2006-02-09 18:38
(Received via mailing list)
just take a look at RJS (at rails edge), this is the easiest way for
multiple partial AJAX page reloads without handcoded javascript
This topic is locked and can not be replied to.