# RJS wierdness - Content div display js code

**URL:** <https://www.ruby-forum.com/t/rjs-wierdness-content-div-display-js-code/62858>\
**Category:** Rails\
**Created:** [June 8, 2006, 8:11pm UTC](https://www.ruby-forum.com/t/rjs-wierdness-content-div-display-js-code/62858 "2006-06-08T20:11:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c57346/32.png) [@sjames](https://www.ruby-forum.com/u/sjames)\
**Post date:** [June 8, 2006, 8:11pm UTC](https://www.ruby-forum.com/t/rjs-wierdness-content-div-display-js-code/62858/1 "2006-06-08T20:11:48Z")

</div>

Hi,

I have a link\_to\_remote name ‘Show notes’, which calls an action that  
uses this RJS template:

page.replace “notes\_remote”, :partial =\> “notes/hide\_notes\_link”  
page.insert\_html :top, “notes\_list”, :template =\> “notes/list”  
page.visual\_effect :highlight, ‘notes\_list’, :duration =\> 3

Works great. The ‘Show notes’ link is replaced with a ‘Hide notes’  
link, and a ‘notes\_list’ div has some content displayed in it. The  
highlight effect works as expected. Except…

The content that is displayed is, wait for it, the generated  
javascript code: (!)

Element.replace(“notes\_remote”, “Hide notes”); new  
Insertion.Top(“notes\_list”, null); new  
Effect.Highlight(“notes\_list”,{duration:3});

I went through Cody F.'s ‘add a fox’ tutorial[1], and it works  
fine. Looking at the headers and content in Firebug, the only  
difference I can see in the tutorial example is that the js code is  
wrapped in a try/catch block.

Content-type is text/javascript, and I am including all the necessary  
js files (as evidenced by the fact that the ajax bits “work”. I have  
also done rake ‘update\_javascripts’.

Fresh eyes appreciated.  
jh

[1] [http://www.codyfauser.com/articles/2005/11/20/rails-rjs-templates](http://www.codyfauser.com/articles/2005/11/20/rails-rjs-templates)

–  
James H.  
Web application developer  
Vancouver, BC

“Developing a coherent political analysis is in many respects  
contingent upon an ability to connect one context to another, a  
process not dissimilar to playing the kid’s game of dot-to-dot.”

- Ward Churchill, from ‘“A Government of Laws”?’

---

<div class="post-metadata">

**Author:** ![sjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c57346/32.png) [@sjames](https://www.ruby-forum.com/u/sjames)\
**Post date:** [June 8, 2006, 8:27pm UTC](https://www.ruby-forum.com/t/rjs-wierdness-content-div-display-js-code/62858/2 "2006-06-08T20:27:30Z")

</div>

James H. wrote:

> The content that is displayed is, wait for it, the generated  
> javascript code: (!)

Make sure you are not using the :update option in the link\_to\_remote.  
The :update takes whatever is returned by the server and sticks it in  
the specified DOM id. SO it’s used when the server returns HTML. When  
the server returns javascript, in the case of RJS, it should simply be  
executed, and the javascript itself decides what gets manipulated.

In case I am wrong, post you link\_to\_remote call cause that might be  
where the problem is.

---

<div class="post-metadata">

**Author:** ![sjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c57346/32.png) [@sjames](https://www.ruby-forum.com/u/sjames)\
**Post date:** [June 8, 2006, 8:39pm UTC](https://www.ruby-forum.com/t/rjs-wierdness-content-div-display-js-code/62858/3 "2006-06-08T20:39:54Z")

</div>

On 6/8/06, Alex W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> In case I am wrong, post you link\_to\_remote call cause that might be  
> where the problem is.

Alex, thanks so much, that was exactly the problem.

Now to figure out why the options\_for\_render param to insert\_html is  
generating null.

jh

–  
James H.  
Web application developer  
Vancouver, BC

“Developing a coherent political analysis is in many respects  
contingent upon an ability to connect one context to another, a  
process not dissimilar to playing the kid’s game of dot-to-dot.”

- Ward Churchill, from ‘“A Government of Laws”?’

---

<div class="post-metadata">

**Author:** ![sjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c57346/32.png) [@sjames](https://www.ruby-forum.com/u/sjames)\
**Post date:** [June 8, 2006, 9:13pm UTC](https://www.ruby-forum.com/t/rjs-wierdness-content-div-display-js-code/62858/4 "2006-06-08T21:13:02Z")

</div>

James H. wrote:

> Alex, thanks so much, that was exactly the problem.
> 
> Now to figure out why the options\_for\_render param to insert\_html is  
> generating null.

because :template is not a valid option? I think you have to use  
partial.
