# RJS page.update question

**URL:** <https://www.ruby-forum.com/t/rjs-page-update-question/153866>\
**Category:** Rails\
**Created:** [November 22, 2008, 1:02am UTC](https://www.ruby-forum.com/t/rjs-page-update-question/153866 "2008-11-22T01:02:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe-black](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joe-black](https://www.ruby-forum.com/u/joe-black)\
**Post date:** [November 22, 2008, 1:02am UTC](https://www.ruby-forum.com/t/rjs-page-update-question/153866/1 "2008-11-22T01:02:37Z")

</div>

How does page.update actually work? I know its a wrapper for  
Prototype.update but how does it get the partial in there?

Say I wanted to update a div with the contents of a partial manually  
like this.

content = render(:partial =\> ‘whatever’)  
page.call “$(‘my\_div’).update(#{content})”

But his does not work. It keeps giving me weird errors about &nbsp;  
tags. Any clues?

---

<div class="post-metadata">

**Author:** ![joe-black](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joe-black](https://www.ruby-forum.com/u/joe-black)\
**Post date:** [November 22, 2008, 3:50pm UTC](https://www.ruby-forum.com/t/rjs-page-update-question/153866/2 "2008-11-22T15:50:09Z")

</div>

On Nov 22, 12:02 am, Joe B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> tags. Any clues?  
> That’s now how you are supposed to use page.call. The first argument  
> is supposed to be the function to call (ie $(‘my\_div’).update) and  
> subsequent arguments are arguments to pass through. What your code  
> does is ask the browser to execute

$(‘my\_div’).update(some html here)  
(assuming that was the html content), ie the string literal is not  
quoted and is just dumped in there. There is no need to use page.call  
here though as page.replace\_html handles this already (see  
[http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html#M001446](http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html#M001446)  
)

Fred

---

<div class="post-metadata">

**Author:** ![joe-black](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joe-black](https://www.ruby-forum.com/u/joe-black)\
**Post date:** [November 22, 2008, 9:32pm UTC](https://www.ruby-forum.com/t/rjs-page-update-question/153866/3 "2008-11-22T21:32:00Z")

</div>

I am aware of page.update and page.replace\_html but I was wondering how  
it actually works.

Basically I have a callback from a scriptaculous effect that will update  
a div with the results of some partial so I can not use the built in  
page.xxx calls.

---

<div class="post-metadata">

**Author:** ![joe-black](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joe-black](https://www.ruby-forum.com/u/joe-black)\
**Post date:** [November 22, 2008, 9:41pm UTC](https://www.ruby-forum.com/t/rjs-page-update-question/153866/4 "2008-11-22T21:41:13Z")

</div>

On Nov 22, 8:32 pm, Joe B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am aware of page.update and page.replace\_html but I was wondering how  
> it actually works.
> 
> Basically I have a callback from a scriptaculous effect that will update  
> a div with the results of some partial so I can not use the built in  
> page.xxx calls.

Your first post rather implied that you could since you were using  
page.call. Anyway, first off you can use update\_page to get an rjs  
like page object anywhere you happen to be. Secondly prototype’s  
update stuff is as simple as $(‘some\_div’).update(‘hello world’). If  
however you are generating the html in rails and then just injecting  
it into some javascript with #{} then you need to quote the string of  
html properly (and if you quote the string with " you need to escape  
any " in the html (and similarly with '). page.call does all that for  
you, there’s a helper whose name I forget that does that and to\_json  
would probably do the trick too.

Fred
