在ajax中呈现的Rails 3表单获取与text_fields值混合的html

时间:2022-08-25 05:02:19

I'm rendering a form by ajax this way:

我用这种方式通过ajax渲染表单:

$('#details').html("<%== escape_javascript(render ('form')) %>");

$('#details')。html(“<%== escape_javascript(render('form'))%>”);

Thanks to d11wtq ! Now the problem is that this form is renderend with some html as text! although all the values in the text-feild and text-area are correct.

感谢d11wtq!现在的问题是这个表单是一个渲染,一些html作为文本!虽然text-feild和text-area中的所有值都是正确的。

This is the form

这是表格

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

So when this form is rendered, after the block <%= @note.wine.name %> Comes Red Wine div> printed out. In the text-field comes the value and some html in it. And the same in the text-area. The html code inserted is always the some, so it's not random. Thanks for your time and your help :)

因此,当渲染此表单时,在块<%= @ note.wine.name%> Comes Red Wine div>之后打印出来。在文本字段中有值和一些html。在文本区域也一样。插入的html代码总是一些,所以它不是随机的。谢谢你的时间和帮助:)

1 个解决方案

#1


0  

$('#details').html("<%= raw escape_javascript(render ('form')) %>")

make sure the raw is passed because some newer versions of rails are having problems escaping java scripts and html at the moment. also make sure you selector is in place. And have a respond to js formart in your controller, and a js.erb template in your view.

确保raw被传递,因为一些较新版本的rails目前无法逃避java脚本和html。还要确保你的选择器到位。并在您的控制器中响应js formart,并在视图中响应js.erb模板。

#1


0  

$('#details').html("<%= raw escape_javascript(render ('form')) %>")

make sure the raw is passed because some newer versions of rails are having problems escaping java scripts and html at the moment. also make sure you selector is in place. And have a respond to js formart in your controller, and a js.erb template in your view.

确保raw被传递,因为一些较新版本的rails目前无法逃避java脚本和html。还要确保你的选择器到位。并在您的控制器中响应js formart,并在视图中响应js.erb模板。