Frage

I am following this tutorial (http://www.tweetegy.com/2013/04/create-nested-comments-in-rails-using-ancestry-gem/) on how to setup the Ancestry gem for nested comments. When I run through the tutorial on a normal rails app it works fine. My issue comes when I try to separate the commenting system out into an engine. Here are the models that I have:

In the engine

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

In the main app

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

If I remove has_ancestry I can access the comments just fine. I have followed the tutorial just as I did in the first app but for some reason when I run Article.first.comments on this one I get the method missing error. Please let me know if I need to include more information for assistance. Thank you.

War es hilfreich?

Lösung

If you are using an engine you should put ancestry in your Gemfile and require it in lib/<your_engine>/engine.rb file.

lib/your_engine/engine.rb

require 'ancestry'
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top