简体   繁体   中英

Rails 3.2 + jQuery + render partial in js.erb = broken HTML elements

The task is pretty simple: render partial template with OnChange AJAX function. After js.erb with render is executed I get broken HTML tags on my page new all rendered elements. In this example it adds 'a>' to the link name, so DOM contains 'New branda>' .

#partial
<%= link_to 'New Brand', new_brand_path %>

#controller-------------------------
...
format.js

#parent view------------------------
<div id="partial-id">
    <%= render 'partial' %>
</div>

#action_script.js.rjs---------------
$("#partial-id").html("<%= escape_javascript(render ('partial')).html_safe %>");

Suggestions will be highly appreciated, I've already spent several hours trying to find out solution.

The problem solved once I switched from Prototype to jQuery . So the *action_script.js.erb* works well and .html_safe is not required in this case.

For us with WODstack we use this quite a lot but we never ever use .html_safe.

Just remove your html_safe and you should be fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM