mongodb 和 Rails 3 中的 ActAsTaggableOn
我想在我的应用程序中添加标记功能。所以,我正在使用acts_as_taggable_on: https://github.com/mbleigh/acts-as- taggable-on
我在 Gemfile 中添加了以下行:
gem 'acts-as-taggable-on', '~> 2.2.2'
当我在用户模型中添加以下行时:
acts_as_taggable_on
它给了我这个错误:
undefined local variable or method `acts_as_taggable_on' for User:Class
请告诉我我做错了什么?
I want to adding tagging facility in my application . so, I am using acts_as_taggable_on : https://github.com/mbleigh/acts-as-taggable-on
I have added following line my Gemfile:
gem 'acts-as-taggable-on', '~> 2.2.2'
and when I add following line in my user model:
acts_as_taggable_on
It gives me this error:
undefined local variable or method `acts_as_taggable_on' for User:Class
Kindly, tell me what am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该 gem 无法与 mongoid 和 mongodb 一起使用,因为它的构建是为了允许使用使用活动记录的关系数据库进行标记。
好消息是,这在 mongoid 中非常简单。只需添加一个新的数组字段,以您列出的任何内容命名为acts_as_taggable_on。如果您还有acts_as_taggable,也请包含一个通用标签字段。
如果您打算有一个如下所示的模型:
您将使用 mongoid 构建它:
然后,当您想要保存标签时,可以说作为兴趣,您将执行以下操作:
That gem isn't going to work with mongoid and mongodb because it is built to allow tagging using a relational database using active record.
The good news is that this is very simple to do in mongoid. Simply add a new Array field named after whatever you would have listed as being acts_as_taggable_on. If you also have acts_as_taggable, include a generic tags field as well.
If you were going to have a model that looked like this:
You would build it like this with mongoid:
Then when you wanted to save a tag, lets say as an interest you would do the following: