我正在使用以下帮助函数,但它似乎将我的
JavaScript语句中的所有特殊字符转换为HTML实体,使其无用且破坏.有什么建议?
def link_to_add_fields(name,f,association) new_object = f.object.class.reflect_on_association(association).klass.new fields = f.fields_for(association,new_object,:child_index => "new_#{association}") do |builder| render(association.to_s + "_fields",:f => builder) end link_to_function(name,h("add_fields(this,\"#{association}\",\"#{escape_javascript(fields)}\")")) end
上面会生成这样的链接(请注意转换为$amp; – & quot;等:
<a href="#" onclick="add_fields(this,&quot;skills&quot;,&quot;&lt;label for=\&quot;user_skills_attributes_new_skills_name\&quot;&gt;Skill&lt;\/label&gt;\n&lt;input data-autocomplete=\&quot;/users/autocomplete_skills_vocab_name\&quot; id=\&quot;user_skills_attributes_new_skills_name\&quot; name=\&quot;user[skills_attributes][new_skills][name]\&quot; size=\&quot;30\&quot; type=\&quot;text\&quot; /&gt;&lt;br /&gt;\n&lt;input id=\&quot;user_skills_attributes_new_skills__destroy\&quot; name=\&quot;user[skills_attributes][new_skills][_destroy]\&quot; type=\&quot;hidden\&quot; value=\&quot;false\&quot; /&gt;&lt;a href=\&quot;#\&quot; onclick=\&quot;remove_fields(this); return false;\&quot;&gt;remove&lt;\/a&gt;&quot;); return false;">Add a Skill</a>
编辑/
想出来 – 对于Rails 3删除h()