# Rjs not executing?

**URL:** <https://www.ruby-forum.com/t/rjs-not-executing/83252>\
**Category:** Rails\
**Created:** [January 24, 2007, 5:52pm UTC](https://www.ruby-forum.com/t/rjs-not-executing/83252 "2007-01-24T17:52:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sayoyo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@sayoyo](https://www.ruby-forum.com/u/sayoyo)\
**Post date:** [January 24, 2007, 5:52pm UTC](https://www.ruby-forum.com/t/rjs-not-executing/83252/1 "2007-01-24T17:52:05Z")

</div>

Hi,

I’m trying to execute a .rjs, but instead of executing the javascript  
code, the javascript code is shown on the html. Does any one know why?

thanks you very much

## Sayoyo

example code:

on main.rhtml, I have:  
\<%= link\_to\_remote(‘add’, :url=\>{:action=\>‘openAdd’},  
:update=\>‘addZone’)-%\>

on MainController.rb I have  
def openAdd  
end

on openAdd.rjs, I have  
page.replace\_html(“addZone”, :partial=\>“openAdd”)

on \_openAdd.rhtml, I have  
“add opened”

after click on “add” on the main.rhtml i got:  
try { Element.update(“addControlZone”, “add opened\n”); } catch (e) {  
alert(‘RJS error:\n\n’ + e.toString());  
alert(‘Element.update(“addControlZone”, “toto\n”);’); throw e }

---

<div class="post-metadata">

**Author:** ![sayoyo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@sayoyo](https://www.ruby-forum.com/u/sayoyo)\
**Post date:** [January 24, 2007, 7:16pm UTC](https://www.ruby-forum.com/t/rjs-not-executing/83252/2 "2007-01-24T19:16:06Z")

</div>

No, you need to do:

class MainController  
def openAdd  
render :partial =\> ‘openAdd’  
end  
end

and rename openAdd.rjs to \_openAdd.rjs.

Jason

---

<div class="post-metadata">

**Author:** ![sayoyo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@sayoyo](https://www.ruby-forum.com/u/sayoyo)\
**Post date:** [January 24, 2007, 6:19pm UTC](https://www.ruby-forum.com/t/rjs-not-executing/83252/3 "2007-01-24T18:19:53Z")

</div>

> Hi,
> 
> I’m trying to execute a .rjs, but instead of executing the javascript  
> code, the javascript code is shown on the html. Does any one know why?

Do you render with :layout =\> false ?

Like:  
render :template =\> ‘logi/ajax\_vote’,  
:layout =\> false

Wybo

---

<div class="post-metadata">

**Author:** ![sayoyo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@sayoyo](https://www.ruby-forum.com/u/sayoyo)\
**Post date:** [January 29, 2007, 4:17pm UTC](https://www.ruby-forum.com/t/rjs-not-executing/83252/4 "2007-01-29T16:17:08Z")

</div>

Thanks you very much for the information, but what exactly the  
difference between Ajax.request and Ajax.update???

Sayoyo

unknown wrote:

> > on main.rhtml, I have:  
> > \<%= link\_to\_remote(‘add’, :url=\>{:action=\>‘openAdd’},  
> > :update=\>‘addZone’)-%\>
> 
> Don’t use the :update option with rjs calls. That constructs an  
> Ajax.Updater prototype object instead of the Ajax.Request object you  
> need for rjs calls.
> 
> On the other hand, if you only need to update one html element, I’d  
> leave the :update option and just return a regular partial template,  
> pretty sure it’s considerably faster.
> 
> Good Luck,  
> Tim

---

<div class="post-metadata">

**Author:** ![sayoyo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@sayoyo](https://www.ruby-forum.com/u/sayoyo)\
**Post date:** [January 29, 2007, 4:45pm UTC](https://www.ruby-forum.com/t/rjs-not-executing/83252/5 "2007-01-29T16:45:51Z")

</div>

The Updater is given a DOM id, which will then be rewritten with the  
response of the request. It’s what you use if you want to use AJAX but  
not  
RJS. The Requester just sends a request. I believe that they can both be  
told to execute the response text as javascript as well.

Jason

---

<div class="post-metadata">

**Author:** ![sayoyo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@sayoyo](https://www.ruby-forum.com/u/sayoyo)\
**Post date:** [January 24, 2007, 8:00pm UTC](https://www.ruby-forum.com/t/rjs-not-executing/83252/6 "2007-01-24T20:00:20Z")

</div>

> on main.rhtml, I have:  
> \<%= link\_to\_remote(‘add’, :url=\>{:action=\>‘openAdd’},  
> :update=\>‘addZone’)-%\>

Don’t use the :update option with rjs calls. That constructs an  
Ajax.Updater prototype object instead of the Ajax.Request object you  
need for rjs calls.

On the other hand, if you only need to update one html element, I’d  
leave the :update option and just return a regular partial template,  
pretty sure it’s considerably faster.

Good Luck,  
Tim
