3

我将mongoid-taggable添加到我的 Gemfile 中,然后添加include Mongoid::Taggable到我的模型中,但收到一条错误消息:

uninitialized constant Mongoid::Taggable::Mongo

错误跟踪:

app/models/recipe.rb:13:in `include'
app/models/recipe.rb:13:in `<class:Recipe>'
app/models/recipe.rb:2:in `<top (required)>'
app/controllers/recipes_controller.rb:11:in `index'

有没有人可以解决这个问题?

4

1 回答 1

1

无需过多挖掘 Mongoid Taggable 的来源,我的猜测是它是为 2.xx 版本的 Mongoid 构建的。在 Mongoid 3.xx 版本中,mongo移除了对 gem 的依赖。似乎没有人在一年多的时间里致力于这个 gem,所以我怀疑它是否支持 Mongoid 的 3.xx 版本。

如果您打算使用此 gem 进行标记,则需要回滚到 Mongoid 的早期版本。2.4.12 是 2.xx 分支中的最后一个稳定版本。

另一种解决方案是使用不同的宝石。我会推荐mongoid-tags-arent-hard。它与 Mongoid 3 兼容,并且运行良好。

于 2012-12-23T17:36:23.403 回答