为什么评论呈现为灰色块,里面没有文字?

Why are comments rendered in grey blocks with no words inside?

我通过这个 youtube 教程对我的名为 Rants with polymorphic model 的帖子添加了评论功能: Comments with Polymorphic Associations.

我看到了rails c中的评论,但我只看到网站上显示的是灰色的空评论块。

这是控制台:

2.5.1 :001 > Rant.first.comments
  Rant Load (0.2ms)  SELECT  "rants".* FROM "rants" ORDER BY "rants"."id" ASC LIMIT ?  [["LIMIT", 1]]
  Comment Load (0.2ms)  SELECT  "comments".* FROM "comments" WHERE "comments"."commentable_id" = ? AND "comments"."commentable_type" = ? LIMIT ?  [["commentable_id", "1"], ["commentable_type", "Rant"], ["LIMIT", 11]]
 => #<ActiveRecord::Associations::CollectionProxy [#<Comment id: 1, commentable_type: "Rant", commentable_id: "1", integer: nil, user_id: nil, reply: "Testing!", created_at: "2018-10-18 08:57:16", updated_at: "2018-10-18 08:57:16">, #<Comment id: 3, commentable_type: "Rant", commentable_id: "1", integer: nil, user_id: nil, reply: "yooo\r\n", created_at: "2018-10-18 11:13:55", updated_at: "2018-10-18 11:13:55">, #<Comment id: 4, commentable_type: "Rant", commentable_id: "1", integer: nil, user_id: nil, reply: "wooooooo\r\n", created_at: "2018-10-18 11:14:11", updated_at: "2018-10-18 11:14:11">, #<Comment id: 14, commentable_type: "Rant", commentable_id: "1", integer: nil, user_id: nil, reply: "aa", created_at: "2018-10-18 16:54:03", updated_at: "2018-10-18 16:54:03">]> 
2.5.1 :002 > exit

app/views/comments/_comments.html.erb是这样的:

<h3>Comments</h3>
<% commentable.comments.each do |comment| %>
  <div class="well">
   <% comment.reply %>
  </div>
<% end %>

灰块是用class = "well"设计的,灰块里面应该有注释。

Comment section image

如果你能告诉我应该在哪里检查,那将对我有很大帮助。

已编辑:

这可能是另一个问题,但我也没有在 table 上显示我的评论。 table image with no comments shown

app/views/rants/index.html.erb是这样的:

<h1>Rants</h1>
<table class="table table-striped">
  <thead>
    <tr>
      <th colspan="2">Title</th>
      <th colspan="2">Gaijintag</th>
      <th class="text-center">Content</th>
      <th class="text-center">Replies</th>
    </tr>
  </thead>
  <tbody>
    <% @rants.each do |rant| %>
      <tr>
        <td colspan="2"><%= rant.title %></td>
        <td colspan="2"><%= rant.gaijintag %></td>
        <td><%= rant.content %></td>
        <td><%= rant.comments %></td>
        <td class="text-right">
          <%= link_to 'Reply', polymorphic_path(rant), :action => :new, :class => 'btn btn-link btn-xs'%>
          <%= link_to 'Edit', edit_rant_path(rant), :class => 'btn btn-link btn-xs' %>
          <%= link_to 'Delete', rant_path(rant), :class => 'btn btn-xs btn-danger',
                          :method => :delete, :data => { :confirm => 'Are you sure?' } %>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>
<%= paginate @rants %>
<br>
<%= link_to 'New Rant', new_rant_path, :class => 'btn btn-primary' %>

app/controllers/comments_controller.rb是这样的:

class CommentsController < ApplicationController
    before_action :authenticate_user!

    def create
        @comment = @commentable.comments.new comment_params
        @comment.save
        redirect_to @commentable, notice: "Your reply was successfully posted!"
    end

    private

        def comment_params
            params.require(:comment).permit(:reply)
        end

end

谢谢。

如果您希望它实际呈现在您的页面上,请使用 <%= 标记:

<%= comment.reply %>