不同用户的独特标签

发布于 2025-01-02 00:10:18 字数 176 浏览 3 评论 0原文

我目前正在调查 ActsAsTaggableOn 是否能满足我的需求。具体来说,我有一个应用程序,用户可以在其中注册和添加人员。他们可以给人们贴上标签。但是,我想将一个用户创建的标签与另一用户创建的标签分开。

这似乎是一个常见的要求,所以我有点惊讶,这显然不是最重要的。这可能吗?如果可以,怎么做?

谢谢!

I'm currently investigating whether ActsAsTaggableOn is going to work for my needs. Specifically, I have an application where users can sign up and add people. They can tag people. However, I want to segregate the tags that one user creates from the tags that another user creates.

It seems like this would be a common requirement, so I'm a little surprised that it's not something obviously front and centre. Is this possible to do, and if so, how?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

又怨 2025-01-09 00:10:18

ActsAsTaggableOn 不支持您需要的功能。我建议滚动您自己的标记系统并使用 ActsAsTaggableOn 作为适当结构的示例。

我会使用类似的结构,只不过标签表还包含一个用户 ID,然后您可以使用该 ID 将标签范围限定到当前用户。

ActsAsTaggableOn does not support the functionality you need. I would recommend rolling your own tagging system and use ActsAsTaggableOn as an example of appropriate structures.

I would use a similar structure, except have the tag table also contain a user id that you could then use to scope tags to the current user.

回忆那么伤 2025-01-09 00:10:18

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.

有帮助。

ActsAsTaggableOn supports making a model acts_as_tagger, which allows you to retrieve the tags they've tagged (https://github.com/mbleigh/acts-as-taggable-on). It seems like this is what you're talking about.

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

Particularly the line

@some_photo.locations_from(@some_user)...etc.

Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文