Forum: Ruby on Rails rjs not executing?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
sayoyo (Guest)
on 2007-01-24 18:52
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')-%>
<div id="addZone"></div>

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 }
Wybo W. (Guest)
on 2007-01-24 19:19
(Received via mailing list)
> 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
Jason R. (Guest)
on 2007-01-24 20:16
(Received via mailing list)
No, you need to do:

class MainController
  def openAdd
    render :partial => 'openAdd'
  end
end

and rename openAdd.rjs to _openAdd.rjs.

Jason
unknown (Guest)
on 2007-01-24 21:00
(Received via mailing list)
> on main.rhtml, I have:
> <%= link_to_remote('add', :url=>{:action=>'openAdd'},
> :update=>'addZone')-%>
> <div id="addZone"></div>
>

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
sayoyo (Guest)
on 2007-01-29 17:17
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')-%>
>> <div id="addZone"></div>
>>
>
> 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
Jason R. (Guest)
on 2007-01-29 17:45
(Received via mailing list)
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
This topic is locked and can not be replied to.