这是acts_as_taggable_on中动态标记上下文文档提供的一些信息......
@user = User.new(:name => "Bobby")
@user.set_tag_list_on(:customs, "same, as, tag, list")
@user.tag_list_on(:customs) # => ["same","as","tag","list"]
@user.save
@user.tags_on(:customs) # => [<Tag name='same'>,...]
@user.tag_counts_on(:customs)
User.tagged_with("same", :on => :customs) # => [@user]
我的问题是如何得到我创建的自定义标记列表的赞美。我想:标签 - :海关,即所有标签的集合减去指定的海关标签。
答案 0 :(得分:1)
从他们的Github页面:
# Find a user that's not tagged with awesome or cool:
User.tagged_with(["awesome", "cool"], :exclude => true)
你可以尝试:
customs_tags = @user.tag_list_on(:customs)
user_tags = @user.tag_list
new_tags = user_tags - customs_tags
@user.set_tag_list_on(:customs, new_tags)