# Is there a way to abstract the updating of other parts of th

**URL:** <https://www.ruby-forum.com/t/is-there-a-way-to-abstract-the-updating-of-other-parts-of-th/61571>\
**Category:** Rails\
**Created:** [May 25, 2006, 3:36am UTC](https://www.ruby-forum.com/t/is-there-a-way-to-abstract-the-updating-of-other-parts-of-th/61571 "2006-05-25T03:36:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@jonny](https://www.ruby-forum.com/u/jonny)\
**Post date:** [May 25, 2006, 3:36am UTC](https://www.ruby-forum.com/t/is-there-a-way-to-abstract-the-updating-of-other-parts-of-th/61571/1 "2006-05-25T03:36:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jonny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@jonny](https://www.ruby-forum.com/u/jonny)\
**Post date:** [May 25, 2006, 4:07am UTC](https://www.ruby-forum.com/t/is-there-a-way-to-abstract-the-updating-of-other-parts-of-th/61571/2 "2006-05-25T04:07:20Z")

</div>

I’m not sure if you can do this with an RJS template, but you should be  
able  
to create a response to an ajax request which contains more ajax  
requests  
which are then executed. I’m sorry this doesn’t give you anything  
concrete,  
but I hope it helps

Daniel

---

<div class="post-metadata">

**Author:** ![jonny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@jonny](https://www.ruby-forum.com/u/jonny)\
**Post date:** [May 25, 2006, 4:16am UTC](https://www.ruby-forum.com/t/is-there-a-way-to-abstract-the-updating-of-other-parts-of-th/61571/3 "2006-05-25T04:16:27Z")

</div>

is there anything wrong with  
page.replace\_html id, :partial =\> ‘somePartial’

?

---

<div class="post-metadata">

**Author:** ![jonny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@jonny](https://www.ruby-forum.com/u/jonny)\
**Post date:** [May 25, 2006, 5:56am UTC](https://www.ruby-forum.com/t/is-there-a-way-to-abstract-the-updating-of-other-parts-of-th/61571/4 "2006-05-25T05:56:10Z")

</div>

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.

-Jonathan

---

<div class="post-metadata">

**Author:** ![jonny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@jonny](https://www.ruby-forum.com/u/jonny)\
**Post date:** [May 25, 2006, 1:09pm UTC](https://www.ruby-forum.com/t/is-there-a-way-to-abstract-the-updating-of-other-parts-of-th/61571/5 "2006-05-25T13:09:11Z")

</div>

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 …  
end  
end  
end

---

<div class="post-metadata">

**Author:** ![jonny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@jonny](https://www.ruby-forum.com/u/jonny)\
**Post date:** [May 25, 2006, 11:44am UTC](https://www.ruby-forum.com/t/is-there-a-way-to-abstract-the-updating-of-other-parts-of-th/61571/6 "2006-05-25T11:44:46Z")

</div>

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  
rjs  
which replaces particular areas (or has a particular branch of logic)  
with  
another rjs partial?

ie

render :partial =\> ‘branch\_one’

\_branch\_one.rjs  
if some logic  
page.replace\_html “thing1”, :partial =\>‘branch\_two’  
page.replace\_html “thing2”, :partial =\>‘branch\_three’  
else  
page.replace\_html “thing1”, :partial =\>“branch4”  
page.replace\_html “thing2”, :partial =\> “branch5”  
end

then you could similarly have logic dedicated to other branches in the  
partials  
\_branch\_two.rjs  
\_branch\_three.rjs  
\_branch4.rjs  
\_branch5.rjs

I’m not sure that this is what you had in mind tho…
