2

我正在关注本教程(http://www.tweetegy.com/2013/04/create-nested-comments-in-rails-using-ancestry-gem/),了解如何为嵌套评论设置 Ancestry gem。当我在普通的 Rails 应用程序上运行本教程时,它工作正常。当我尝试将评论系统分离到引擎中时,我的问题就出现了。以下是我拥有的模型:

在发动机

module CommentThread
  class Comment < ActiveRecord::Base
    has_ancestry
    belongs_to :commentable, :polymorphic => true
  end
end

在主应用程序中

class Article < ActiveRecord::Base
  has_many :comments, :as => :commentable, class_name: 'CommentThread::Comment'
end

如果我删除has_ancestry,我可以访问评论就好了。就像我在第一个应用程序中所做的那样,我已经按照教程进行操作,但是由于某种原因,当我在这个应用程序上运行 Article.first.comments 时,我得到了方法丢失错误。如果我需要提供更多信息以获得帮助,请告诉我。谢谢你。

4

1 回答 1

2

如果您使用的是引擎,您应该将祖先放在您的 Gemfile 中并在lib/<your_engine>/engine.rb file.

lib/your_engine/engine.rb

require 'ancestry'
于 2013-10-16T14:45:10.233 回答