Inserting Javascript dinamically with DOM

I want to do simple stuff. In my controller I have this:

render :update do |page|
page.replace_html ‘scripts’, :partial => ‘scripts’, :locals =>
{:question => @question}
end

And in the partial I have this:

<% if question.sound %>
Sound loaded!

<% end %>

Well, when I run it, the message “Sound loaded!” appears, but the
scripts are not rendered (I inspect the elements with Chrome and with
Firebug, and the scripts do not appear).

Is there anything wrong when I try to do this? Is there a way to make
this work?

Yuri Albuquerque wrote:

I want to do simple stuff. In my controller I have this:

render :update do |page|
page.replace_html ‘scripts’, :partial => ‘scripts’, :locals =>
{:question => @question}
end

And in the partial I have this:

<% if question.sound %>
Sound loaded!

<% end %>

Well, when I run it, the message “Sound loaded!” appears, but the
scripts are not rendered (I inspect the elements with Chrome and with
Firebug, and the scripts do not appear).

Is there anything wrong when I try to do this? Is there a way to make
this work?

Why not just call the script file from a tag instead of
replace_html? In general, your JavaScript should be coming from static
external files.

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Why not just call the script file from a

And this on the controller:

  page << 'soundManager.unload();'
  page << "q_sound = '#{url_for_file_column('question', :sound)}';"
  page << 'soundManager.load();'

But when I test, it return this error:

RJS error:

Error: SoundManager.getSoundById(): sID is null/undefined

I know why this error is ocurring (because soundManager is trying to
load q_sound even if it is empty), but I don’t know how to solve.

Any tips?

Yuri Albuquerque wrote:

Why not just call the script file from a

And this on the controller:

  page << 'soundManager.unload();'
  page << "q_sound = '#{url_for_file_column('question', :sound)}';"
  page << 'soundManager.load();'

But when I test, it return this error:

RJS error:

Error: SoundManager.getSoundById(): sID is null/undefined

I know why this error is ocurring (because soundManager is trying to
load q_sound even if it is empty), but I don’t know how to solve.

Any tips?

Follow the advice I already gave.

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs