Rjs not executing?


#1

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 }


#2

No, you need to do:

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

and rename openAdd.rjs to _openAdd.rjs.

Jason


#3

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


#4

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


#5

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


#6

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