# RJS -- What am I missing?

**URL:** <https://www.ruby-forum.com/t/rjs-what-am-i-missing/96300>\
**Category:** Rails\
**Created:** [June 28, 2006, 12:07am UTC](https://www.ruby-forum.com/t/rjs-what-am-i-missing/96300 "2006-06-28T00:07:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![al-evans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@al-evans](https://www.ruby-forum.com/u/al-evans)\
**Post date:** [June 28, 2006, 12:07am UTC](https://www.ruby-forum.com/t/rjs-what-am-i-missing/96300/1 "2006-06-28T00:07:43Z")

</div>

This is driving me nuts:-)

I’ve brought it down to a simplified case where I’m rendering this rjs  
template:

page.insert\_html :top, ‘cat1’, “

- Some list item
”

According to FireBug, this is what I’m actually getting in the browser:

try {  
new Insertion.Top(“cat1”, “

- Some list item
”);  
} catch (e) { alert(‘RJS error:\n\n’ + e.toString()); alert(‘new  
Insertion.Top(“cat1”, “- Some list item
”);’); throw e }

This all looks right to me, though I’m no Javascript expert. The headers  
have  
Content-Type: text/javascript.

But what is actually being displayed instead of a new list item is  
something like:

try { new Insertion.Top(“cat1”, "  
o Some list item  
"); } catch (e) { alert(‘RJS error:\n\n’ + e.toString()); alert(‘new  
Insertion.Top(“cat1”, "  
o Some list item  
");’); throw e }

(…where the o’s represent the little list-item dots – the two  
instances of “Some list item” are actually being displayed as list  
items).

Can anybody throw a clue to a clueless man?

Thanks in advance!

–Al Evans

---

<div class="post-metadata">

**Author:** ![al-evans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@al-evans](https://www.ruby-forum.com/u/al-evans)\
**Post date:** [June 28, 2006, 12:12am UTC](https://www.ruby-forum.com/t/rjs-what-am-i-missing/96300/2 "2006-06-28T00:12:36Z")

</div>

## If you are using :update =\> ‘someid’ in your link\_to\_remote this will happen. See if that’s the cause.

View this message in context:  
[http://www.nabble.com/RJS----What-am-I-missing--tf1858282.html#a5075103](http://www.nabble.com/RJS----What-am-I-missing--tf1858282.html#a5075103)  
Sent from the RubyOnRails Users forum at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![al-evans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@al-evans](https://www.ruby-forum.com/u/al-evans)\
**Post date:** [June 28, 2006, 12:12am UTC](https://www.ruby-forum.com/t/rjs-what-am-i-missing/96300/3 "2006-06-28T00:12:58Z")

</div>

I recently ran into this, though it’s an easy fix. Whatever the remote  
call is (link\_to\_remote, form\_remote\_tag, etc) have a first parameter of  
which DOM element to update. The RJS returns the javascript string, so  
the Ajax call promplty updates that element with the new text. However,  
RJS want’s to update elements itself.

So just give the remote link a blank string where it asks for an element  
to update, e.g.: link\_to\_remote ‘’, url\_stuff

Jason

---

<div class="post-metadata">

**Author:** ![al-evans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@al-evans](https://www.ruby-forum.com/u/al-evans)\
**Post date:** [June 28, 2006, 12:14am UTC](https://www.ruby-forum.com/t/rjs-what-am-i-missing/96300/4 "2006-06-28T00:14:42Z")

</div>

Al Evans wrote:

> This is driving me nuts:-)
> 
> I’ve brought it down to a simplified case where I’m rendering this rjs  
> template:
> 
> page.insert\_html :top, ‘cat1’, “
> 
> - Some list item
> ”

> But what is actually being displayed instead of a new list item is  
> something like:
> 
> try { new Insertion.Top(“cat1”, "  
> o Some list item  
> "); } catch (e) { alert(‘RJS error:\n\n’ + e.toString()); alert(‘new  
> Insertion.Top(“cat1”, "  
> o Some list item  
> ");’); throw e }
> 
> –Al Evans

Remove the :update portion of your link\_to\_remote tag. :update says  
“shove whatever the result is into the element with id=‘foo’”. You just  
want the javascript to execute, so take out the :update and let it do  
its thang.

---

<div class="post-metadata">

**Author:** ![al-evans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@al-evans](https://www.ruby-forum.com/u/al-evans)\
**Post date:** [June 28, 2006, 12:16am UTC](https://www.ruby-forum.com/t/rjs-what-am-i-missing/96300/5 "2006-06-28T00:16:09Z")

</div>

Al Evans wrote:

> new Insertion.Top(“cat1”, “
> 
> - Some list item
> ”);  
> try { new Insertion.Top(“cat1”, "  
> Can anybody throw a clue to a clueless man?
> 
> Thanks in advance!
> 
> –Al Evans

What does your controller look like for the involved actions? Are you  
doing a remote call (what you should be doing) or are you just doing a  
normal action call? It sounds like your rjs is correct but your  
controller is not rendering what you want.

Matthew M.  
[blog.mattmargolis.net](http://blog.mattmargolis.net)

---

<div class="post-metadata">

**Author:** ![al-evans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@al-evans](https://www.ruby-forum.com/u/al-evans)\
**Post date:** [June 28, 2006, 12:27am UTC](https://www.ruby-forum.com/t/rjs-what-am-i-missing/96300/6 "2006-06-28T00:27:39Z")

</div>

Alex W. wrote:

> Remove the :update portion of your link\_to\_remote tag. :update says  
> “shove whatever the result is into the element with id=‘foo’”. You just  
> want the javascript to execute, so take out the :update and let it do  
> its thang.

Thanks! That was the problem. I knew it had to be something simple.

Stupid newbie tricks… 🙂

–Al Evans
