开发者

rails 2 replace_html puts javascript into the page

开发者 https://www.devze.com 2023-02-04 09:13 出处:网络
In my controller I have: respond_to do |format| format.js end In my rjs: page.replace_html(\"source_credential_list\", :partial => \"source_credential_list\", :object => @all_source_credenti

In my controller I have:

  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 %>

In my orig view:

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

When I do replace it works great, but only one time, the 2nd time I get a alert with a null, I suspect because the span is gone. If I do replace_html, it kinda works, it updates the span but it puts the actual rjs/javascript into the span including the new select/drop down. So something like this:

Source credential 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 }

I tried moving the span into the partial and doing both combos, but nothing working. Im sure its something obvious....


I'm not sure what piece of code is triggering this action, but assuming it's triggered by a link_to_remote call, make sure you don't have an :update => "source_credential_list" parameter in your link_to_remote call -- otherwise it will both execute the RJS and update the element specified with the javascript code.

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

Also, when you do page.replace, it only works once because page.replace replaces the specified element, including the surrounding tags, so unless the partial you specify includes the span tag, it'll disappear the first time it's used.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号