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.
7efa1e84afccfab2ab6c528afae4d2aa?d=identicon&s=25 sayoyo (Guest)
on 2007-01-24 17: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 }
F3158b6c62d112e4aba9579953e925db?d=identicon&s=25 Wybo Wiersma (wybo)
on 2007-01-24 18: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
83ca41657a99b65d99889abe712ba5e2?d=identicon&s=25 Jason Roelofs (Guest)
on 2007-01-24 19: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
Ab0b702e7fcc79bb7d2c6c67f64e1b4d?d=identicon&s=25 unknown (Guest)
on 2007-01-24 20: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
7efa1e84afccfab2ab6c528afae4d2aa?d=identicon&s=25 sayoyo (Guest)
on 2007-01-29 16: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
83ca41657a99b65d99889abe712ba5e2?d=identicon&s=25 Jason Roelofs (Guest)
on 2007-01-29 16: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.