我正在尝试将祖先添加到我拥有的Event_Tags模型中。 现在该模型只有一个名称。 我将"祖先"添加到宝石文件中并捆绑在一起。 现在,当我去运行以下命令时:
rails g migration AddAncestryToEventTags ancestry:string
我收到以下错误:
/Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/ancestry- 2.0.0/lib/ancestry/has_ancestry.rb:7:in `block in has_ancestry': Unknown option for has_ancestry: :hierarchy_class_name => "TagHierarchy". (Ancestry::AncestryException)
不知道为什么会出现这种情况。 我一直在关注Ancestry railscast这一集以及文档。
这也是我在尝试运行 rails 控制台时遇到的相同错误。
以下是整个消息:
/Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/ancestry-2.0.0/lib/ancestry/has_ancestry.rb:7:in `block in has_ancestry': Unknown option for has_ancestry: :hierarchy_class_name => "TagHierarchy". (Ancestry::AncestryException)
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/ancestry-2.0.0/lib/ancestry/has_ancestry.rb:5:in `each'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/ancestry-2.0.0/lib/ancestry/has_ancestry.rb:5:in `has_ancestry'
from /Users/stevenbrooks1111/Code/freelance/GRN-Auth/config/initializers/tag_patch.rb:3:in `<class:Tag>'
from /Users/stevenbrooks1111/Code/freelance/GRN-Auth/config/initializers/tag_patch.rb:2:in `<module:ActsAsTaggableOn>'
from /Users/stevenbrooks1111/Code/freelance/GRN-Auth/config/initializers/tag_patch.rb:1:in `<top (required)>'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `block in load'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.11/lib/rails/engine.rb:588:in `block (2 levels) in <class:Engine>'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.11/lib/rails/engine.rb:587:in `each'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.11/lib/rails/engine.rb:587:in `block in <class:Engine>'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `run'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.11/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `each'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.11/lib/rails/application.rb:136:in `initialize!'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/stevenbrooks1111/Code/freelance/GRN-Auth/config/environment.rb:14:in `<top (required)>'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `block in require'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.11/lib/rails/application.rb:103:in `require_environment!'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.11/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
一个可能的原因,在我的例子中是正确的,有两种不同的引擎使用祖先和acts_as_tree。引擎 1,需要 gemspec 的祖先。引擎 2,需要 gemspec 中的acts_as_tree。
如果在 gemfile 中引擎 1 位于引擎 2 之上,则首先加载祖先宝石。在这种情况下,此代码将执行并重写acts_as_tree函数。解决此问题的一种方法是将引擎 2 放在 gemfile 中的引擎 1 上。
我一直无法找到更好的方法来解决此问题,如果您意识到这一点,请告诉我。