尝试为我的讨论模型实现acts_as_commentable gem 时出现以下服务器日志错误:
NameError - uninitialized constant Discussion::Comment:
我已经从自述文件中生成了迁移文件并运行了 rails db:migrate。
rails generate acts_as_commentable_with_threading_migration
我已经尝试重新启动应用程序。
我已按照阅读我的使用说明将其添加到我的模型文件中:
class Discussion < ApplicationRecord
acts_as_commentable
end
尝试显示 Discussion 模型的评论列表的视图代码摘要:
<% Discussion.where(guide_id: @guide.id).order(:created_at).each do|discussion| %>
<% discussion.comment_threads.each do |comment| %>
<p><%= comment.body %></p>
<% end %>
<% end %>
schema.rb 文件包括通过 gem 自述文件中的迁移添加的注释模型:
create_table "comments", force: :cascade do |t|
t.integer "commentable_id"
t.string "commentable_type"
t.string "title"
t.text "body"
t.string "subject"
t.integer "user_id", null: false
t.integer "parent_id"
t.integer "lft"
t.integer "rgt"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["commentable_id", "commentable_type"], name: "index_comments_on_commentable_id_and_commentable_type"
t.index ["user_id"], name: "index_comments_on_user_id"
end