Rails 2 replace_html put javascript on page

In my controller, I:

  respond_to do |format|
    format.js
  end

In my rjs:

page.replace_html("source_credential_list", :partial => "source_credential_list", :object => @all_source_credentials) 

or

page.replace("source_credential_list", :partial => "source_credential_list", :object => @all_source_credentials) 

In my partial :(

<% fields_for(@brand_report_source_credential_key) do |ff|  %>
   <%= ff.select :source_credential_id , options_from_collection_for_select(@all_source_credentials,'id','credential_display_name')%>
<% end %>

From my point of view:

  <span id="source_credential_list">
    <%= render :partial => 'source_credential_list' %>
  </span>

When I replace it, it works fine, but only once, the second time when I get a warning with a zero value, I suspect because the space has disappeared. If I do replace_html, it works, it updates the range, but it puts the actual rjs / javascript in the range, including the new select / drop down. So something like this:

Source credentials try {Element.update ("source_credential_list", "\ n \ n \ n"); } catch (e) {alert ('RJS Error: \ n \ n' + e.toString ()); alert ('Element.update (\ "source_credential_list \", \ "\ n \ n \ n \");'); throw e}

, . , - ....

+3
1

, , , , link_to_remote, , : update = > "source_credential_list" link_to_remote, RJS , javascript-.

: http://railsforum.com/viewtopic.php?pid=44191#p44191

, page.replace, , page.replace , , span, .

+1

Source: https://habr.com/ru/post/1784443/


All Articles