html - 意外的keyword_ensure,期待输入结束

标签 html ruby-on-rails-4

我是 Ruby on Rails 的新手,我正在尝试创建一个具有组的网站,组有帖子,帖子有评论,每当我尝试运行我的代码时,它都会显示以下错误:

语法错误,意外的keyword_ensure,期望输入结束 在评论 View 中指向这部分代码:

    <h2>Add a comment:</h2>
    <%= render'comments/form' %>

谁能告诉我我的代码有什么问题吗?

这是我的代码:

群组显示 View :

    <p>
      <strong>Name:</strong>
      <%= @group.name %>
    </p>

    <p>
      <strong>Description:</strong>
      <%= @group.description %>
    </p>

    <p>
      <strong>Interest:</strong>
      <%= @group.interest %>
    </p>


    <h2>Posts</h2>
    <% @group.posts.each do |post| %>
      <% @post = post %>
      <% if @post != nil %>
        <%= render 'posts/post',  :collection => @group.posts%>
      <% end %> 
    <% end %>

    <h2>Add a Post</h2>
    <%= render 'posts/new' %>

    <%= link_to 'Edit', edit_group_path(@group) %> |
    <%= link_to 'Back', groups_path %>
    <%= link_to 'Destroy', edit_group_path, method: :delete, data: { confirm: 'Are you sure?' } %>

_post.html.erb:

    <p>
      <strong>Title:</strong>
      <%= @post.title %>
    </p>

    <p>
      <strong>Text:</strong>
      <%= @post.text %>
    </p>

     <h2>Comments:</h2>
     <% @post.comments.each do |comment| %>
        <% @comment = comment %>
        <% if @comment != nil %>
            <%= render 'comments/comment',  :collection => @post.comments%>
        <% end %>
      <% end %>

    <h2>Add a comment:</h2>
    <%= render 'comments/form' %>


    <%= link_to 'Show', comment %>
    <%= link_to 'Edit', edit_group_post_path(p@ost) %>
    <%= link_to 'Destroy', edit_group_post_path, method: :delete, data: { confirm: 'Are you sure?' } %>

帖子:_form.html.erb:

    <%= form_for(@post) do |f| %>
  <% if @post.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>

      <ul>
      <% @post.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <h2>Add a post:</h2>
<%= form_for([@group, @group.posts.build]) do |f| %>
  <p>
    <%= f.label :Title %><br>
    <%= f.text_field :title %>
  </p>
  <p>
    <%= f.label :Text %><br>
    <%= f.text_area :text %>
  </p>
  <p>
    <%= f.submit %>
  </p>
<% end %>

_comment.html.erb:

      <p>
        <strong>Commenter:</strong>
        <%= @comment.commenter %>
      </p>

      <p>
        <strong>Comment:</strong>
        <%= @comment.comment %>
      </p>


    <%= link_to 'Edit', edit_group_post_comment_path(@comment) %>
    <%= link_to 'Destroy', edit_group_post_comment_path, method: :delete, data: { confirm: 'Are you sure?' } %>

评论:_form.html.erb:

     <%= form_for([@group,@post, @post.comments.build]) do |f| %>
        <p>
          <%= f.label :comment %><br>
          <%= f.text_area :comment %>
        </p>
        <p>
           <%= f.submit %>
        </p>
      <% end %>
    <% end %> 

最佳答案

您没有关闭 posts/_form.html.erb 中的第一个 form_for block 。

<%= form_for(@post) do |f| %>
  <% if @post.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>

      <ul>
      <% @post.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>
<% end %>   <---- you're missing this tag

关于html - 意外的keyword_ensure,期待输入结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23503163/

相关文章:

Javascript 滚动到 div id

javascript - 使用Javascript抓取远程页面上的元素

ruby - 有没有办法在 ruby​​ 中指定类不可扩展?

ruby-on-rails - Ruby on Rails 中的动态路由设置,如 Facebook

javascript - 为什么 javascript 只换行一次(第一次)?

html - 通过应用长度和高度来解构图像

ruby-on-rails - rails 4 -- 连接 collection_select 中的字段

ruby-on-rails - Rails 路由 : Nested, 成员、集合、命名空间、范围和可定制

javascript - Rails 4 - 嵌套表单和选择选择

Android WebView整页div