# Weird prototype error when using RJS

**URL:** <https://www.ruby-forum.com/t/weird-prototype-error-when-using-rjs/60836>\
**Category:** Rails\
**Created:** [May 17, 2006, 9:05pm UTC](https://www.ruby-forum.com/t/weird-prototype-error-when-using-rjs/60836 "2006-05-17T21:05:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![esquilax](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e0b2c6/32.png) [@esquilax](https://www.ruby-forum.com/u/esquilax)\
**Post date:** [May 17, 2006, 9:05pm UTC](https://www.ruby-forum.com/t/weird-prototype-error-when-using-rjs/60836/1 "2006-05-17T21:05:49Z")

</div>

I’m trying to set up a nested menu strucutre using RJS

I want to be click on an item, have not have the whole page refresh but  
just have the menu

- 1 - my model is using :acts\_as\_tree

- \<%= link\_to\_remote selection.name, :update =\> "Selection", :url =\> {:action =\> :renderMenu, :id =\> selection.id} %\> 

4- my layout provides the following strucutre:

 \<%= render :partial =\> 'selection', :collection =\> @menu[:BreadCrumb][-1].children %\> 

-------anyways 🙂 so this is hte problem i’m having:  
it sort of works but I think i’m getting a prototype error…when I  
click on a parent element to see its children, I get a mix of what I  
want and an error message…all mixed up

try { Element.update(“Selection”, "  
  
"); } catch (e) { alert(‘RJS error:\n\n’ + e.toString());  
alert(‘Element.update(“Selection”, "  
  
");’); throw e }

any suggestions?

---

<div class="post-metadata">

**Author:** ![esquilax](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e0b2c6/32.png) [@esquilax](https://www.ruby-forum.com/u/esquilax)\
**Post date:** [May 17, 2006, 9:18pm UTC](https://www.ruby-forum.com/t/weird-prototype-error-when-using-rjs/60836/2 "2006-05-17T21:18:47Z")

</div>

Andrew G. wrote:

> try { Element.update(“Selection”, "  
>   
> "); } catch (e) { alert(‘RJS error:\n\n’ + e.toString());  
> alert(‘Element.update(“Selection”, "  
>   
> ");’); throw e }

That try/catch stuff is just there for RJS debugging. So that when some  
javascript error occurrs you will get an alert with the details of the  
error.

But is the javascript actually executing? or is it just showing up on  
the page as text? If it’s showing up as text you need to set:

@headers[‘Content-Type’] = ‘text/javascript’

Although if you use “render :update” that should be done for you. Get  
the Firebug extension for Firefox so you can examine the headers and  
content of the response to your ajax calls. It should help you figure  
out whats going on.

---

<div class="post-metadata">

**Author:** ![esquilax](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e0b2c6/32.png) [@esquilax](https://www.ruby-forum.com/u/esquilax)\
**Post date:** [May 17, 2006, 9:24pm UTC](https://www.ruby-forum.com/t/weird-prototype-error-when-using-rjs/60836/3 "2006-05-17T21:24:43Z")

</div>

the javascript is executing…the child elements are apeparing…but  
they’re being around by the javascript error handling output

Alex W. wrote:

> Andrew G. wrote:
> 
> > try { Element.update(“Selection”, "  
> >   
> > "); } catch (e) { alert(‘RJS error:\n\n’ + e.toString());  
> > alert(‘Element.update(“Selection”, "  
> >   
> > ");’); throw e }
> 
> That try/catch stuff is just there for RJS debugging. So that when some  
> javascript error occurrs you will get an alert with the details of the  
> error.
> 
> But is the javascript actually executing? or is it just showing up on  
> the page as text? If it’s showing up as text you need to set:
> 
> @headers[‘Content-Type’] = ‘text/javascript’
> 
> Although if you use “render :update” that should be done for you. Get  
> the Firebug extension for Firefox so you can examine the headers and  
> content of the response to your ajax calls. It should help you figure  
> out whats going on.

---

<div class="post-metadata">

**Author:** ![esquilax](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e0b2c6/32.png) [@esquilax](https://www.ruby-forum.com/u/esquilax)\
**Post date:** [May 17, 2006, 10:38pm UTC](https://www.ruby-forum.com/t/weird-prototype-error-when-using-rjs/60836/4 "2006-05-17T22:38:01Z")

</div>

AAAAh… thanks 🙂 the :update did the trick

Michael T. wrote:

> a couple of things. First you’re not just updating the
> 
> - , you’re  
> updating the whole ordered lists. In your partial you don’t need the  
> :update symbol in there. Finally, like the other poster said, get  
> Firebug. Turn on the Options \>\> ShowXHTMLRequests. View your Console  
> and look at the Request as well as the Response. I suspect you’ll  
> find the problem.
> 
> Michael

---

<div class="post-metadata">

**Author:** ![esquilax](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e0b2c6/32.png) [@esquilax](https://www.ruby-forum.com/u/esquilax)\
**Post date:** [May 17, 2006, 10:28pm UTC](https://www.ruby-forum.com/t/weird-prototype-error-when-using-rjs/60836/5 "2006-05-17T22:28:40Z")

</div>

a couple of things. First you’re not just updating the

- , you’re  
updating the whole ordered lists. In your partial you don’t need the  
:update symbol in there. Finally, like the other poster said, get  
Firebug. Turn on the Options \>\> ShowXHTMLRequests. View your Console  
and look at the Request as well as the Response. I suspect you’ll  
find the problem.

Michael
