Forum: Ruby on Rails Is there a way to abstract the updating of other parts of th

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Jonathan V. (Guest)
on 2006-05-25 05:36
(Received via mailing list)
Hey all,

I'd like to abstract the process of updating different portions of the
page after an Ajax request has taken place. Rather than simply putting
the extra view logic in the standard rjs template, it seems to give
better separation if there is a split between the core view logic (ie,
inserting a row in a table), and updating any associated portions of
the page.

Is this possible? I can't see a way of doing it at the moment because
render can only be called once. I could just fiddle with the RJS stuff
in ActionView but would like to check there isn't a better way.

Maybe an after_filter, but I'm doubtful about that.

Thanks, -Jonathan.
Daniel H. (Guest)
on 2006-05-25 06:07
(Received via mailing list)
I'm not sure if you can do this with an RJS template, but you should be
to create a response to an ajax request which contains more ajax
which are then executed.  I'm sorry this doesn't give you anything
but I hope it helps

Daniel -. (Guest)
on 2006-05-25 06:16
(Received via mailing list)
is there anything wrong with
page.replace_html id, :partial => 'somePartial'

Jonathan V. (Guest)
on 2006-05-25 07:56
(Received via mailing list)
Yep, that's what I'm doing at the moment.

The reason I want the separation is that the application relies
heavily on Ajax so there are often quite a number of page areas that
need to be changed. It would be nice to be able to separate the
updating code from the rest of the rjs code.

Daniel -. (Guest)
on 2006-05-25 13:44
(Received via mailing list)
I'm not sure that I understand the distinction your trying to make.

Could what your trying to achive  be done by calling render on a partial
which replaces particular areas (or has a particular branch of logic)
another rjs partial?


render :partial => 'branch_one'

if some logic
  page.replace_html "thing1", :partial =>'branch_two'
  page.replace_html "thing2", :partial =>'branch_three'
  page.replace_html "thing1", :partial =>"branch4"
  page.replace_html "thing2", :partial => "branch5"

then you could similarly have logic dedicated to other branches in the

I'm not sure that this is what you had in mind tho..
Chris H. (Guest)
on 2006-05-25 15:09
(Received via mailing list)
you also have the option of rendering the rjs directly within the action

def some_action
  if request.xhr?
    render :update do |page|
      case @param[:do]
        when 'foo'
          page.replace_html ...
        when 'bar'
          page.replace_html ...
This topic is locked and can not be replied to.