我目前正在调查ActsAsTaggableOn是否能满足我的需求。具体来说,我有一个应用程序,用户可以在其中注册和添加人员。他们可以给人贴标签。但是,我希望将一个用户创建的标签与另一个用户创建的标签分开。
这似乎是一个常见的要求,所以我有点惊讶,它不是明显的前端和中心的东西。这有可能做到吗?如果可能,如何做到?
谢谢!
发布于 2012-02-03 23:15:57
ActsAsTaggableOn不支持您需要的功能。我建议使用您自己的标签系统,并使用ActsAsTaggableOn作为适当结构的示例。
我将使用类似的结构,只是让标签表也包含一个用户id,然后您可以使用它来将标记的范围扩大到当前用户。
发布于 2012-02-03 23:47:19
ActsAsTaggableOn支持创建模型acts_as_tagger,这允许您检索它们已标记的标记(https://github.com/mbleigh/acts-as-taggable-on)。看起来这就是你所说的。
class User < ActiveRecord::Base
acts_as_tagger
end
class Photo < ActiveRecord::Base
acts_as_taggable_on :locations
end
@some_user.tag(@some_photo, :with => "paris, normandy", :on => :locations)
@some_user.owned_taggings
@some_user.owned_tags
@some_photo.locations_from(@some_user) # => ["paris", "normandy"]
@some_photo.owner_tags_on(@some_user, :locations) # => [#<ActsAsTaggableOn::Tag id: 1, name: "paris">...]
@some_photo.owner_tags_on(nil, :locations) # => Ownerships equivalent to saying @some_photo.locations
@some_user.tag(@some_photo, :with => "paris, normandy", :on => :locations, :skip_save => true) #won't save @some_photo object尤其是这条线
@some_photo.locations_from(@some_user)...etc.希望这能有所帮助。
https://stackoverflow.com/questions/9130783
复制相似问题