以ajax呈现的Rails 3表单将html与text_fields值混合在一起
||
我通过ajax渲染表单:
$(\'#details\').html(\"<%== escape_javascript(render (\'form\')) %>\");
感谢d11wtq!
现在的问题是,这种形式的renderend带有一些html作为文本!尽管text-field和text-area中的所有值都是正确的。
这是表格
<%= form_for @note, :remote => true, :html => { :\'data-type\' => \'html\', :id => \'new-note-form\' } do |f| %>
<% if @note.errors.any? %>
<div id=\"error_explanation\">
<h2><%= pluralize(@note.errors.count, \"error\") %> prohibited this note from being saved:</h2>
<ul>
<% @note.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.hidden_field :wine_id, :value=>@note.wine.id %>
<%= @note.wine.name %>
<div class=\"field\">
<%= f.label :rating %> <br />
<%= f.text_field :rating %> </div>
<div class=\"field\">
<%= f.label :text %> <br />
<%= f.text_area :text,:size => \"60x12\" %>
</div>
<div class=\"actions\">
<%= f.submit %>
</div>
<% end %>
因此,当呈现此表单时,在打印出<%= @ note.wine.name%> Comes Red Wine div>块之后。在文本字段中是值和一些html。和在文本区域中一样。插入的html代码始终是一些,因此不是随机的。
感谢您的时间和您的帮助:)
没有找到相关结果
已邀请:
1 个回复
外镶受继
确保原始文件已通过,因为目前一些较新版本的rails在转义Java脚本和html时遇到问题。还请确保选择器到位。并在您的控制器中响应js formart,并在视图中响应js.erb模板。