0

我正在尝试显示评论列表和使用 AJAX 发表新评论的表单。simple_form_for 块给出以下错误:ArgumentError in DeliveryNegotiations#show Showing /home/action/socialpost/app/views/delivery_negotiations/show.js.erb where line #10 raise: Missing block

这是 show.js.erb 文件:

$("#conversation").html(
    '<% @comments.each do |com| %> \
        <strong> <%=j "User " + com.author_id.to_s + ":" %> </strong> \
        <%=j (com.comment || " ") %> \
        <br/> \
    <% end %> \
  <fieldset> \
    <legend> \
      New comment \
    </legend> \
    <%=j form_for ([@delivery_request, @delivery_negotiation, @comment]) do |builder| %> \
      <%=j builder.text_area :comment %> \
      <%=j builder.hidden_field :author_id, value: current_user.id %> \
      <%=j builder.submit %> \
    <% end %> \
  </fieldset>\
');

任何帮助将不胜感激。

4

1 回答 1

0

请将代码放在一个部分并从 js.erb 文件中渲染,因为它很容易进行更改。

在 _comments_form.html.erb

  <% @comments.each do |com| %>
      <strong> <%= "User " + com.author_id.to_s + ":" %> </strong> 
      <%= (com.comment || " ") %>
      <br/>
  <% end %>


  <fieldset> 
    <legend> 
      New comment
    </legend> 
    <%= form_for ([@delivery_request, @delivery_negotiation, @comment]) do |builder| %> 
      <%= builder.text_area :comment %> 
      <%= builder.hidden_field :author_id, value: current_user.id %> 
      <%= builder.submit %>
    <% end %> 
  </fieldset>

在你的 js.erb 文件中

$("#conversation").html("<%=escape_javascript(render 'comments_form')%>");

我希望这能帮到您。

于 2013-07-31T13:16:36.247 回答