:any标志是否会覆盖acts_as_taggable_on的agged_with中的:on(上下文)标志? [英] Does the :any flag overwrites the :on (context) flag in acts_as_taggable_on's tagged_with?
问题描述
我对flags:on和:any如何在acts_as_taggable_on的"tagged_with"方法中一起工作感到困惑.
I'm confused with how the flags :on and :any works together in the "tagged_with" method of acts_as_taggable_on.
例如,如果我有以下用户@ user1和@ user2:
For example, if I have the following users @user1 and @user2:
class User < ActiveRecord::Base
acts_as_taggable_on :skills, :interests
end
@user1 = User.new(:name => "Bobby")
@user1.interest_list = "1, 15"
@user1.skill_list = "2, 17"
@user1.save
@user2 = User.new(:name => "Al")
@user2.interest_list = "3, 10"
@user2.skill_list = "4, 6"
@user2.save
当我想让所有感兴趣列表的用户都包含[[2],"50"]标签时,我尝试了以下方法:
When I want to get all users who's interest-list include any of the tag ["2", "50"], i tried this:
User.tagged_with(["2", "50"], :on => :interests, :any => true)
问题是我返回@ user1(在skill_list中有"2",而不是interest_list),即使我没有期望.似乎标志:any可能已经覆盖了标志:on.有没有一种方法可以实际执行我上面描述的过滤器?
The problem is I get back @user1 (which has "2" in the skill_list, not interest_list), even though I was expecting none. It seems that the flag :any might have overwritten the flag :on. Is there a way to actually perform the filter I described above?
另外,还有一个问题是,如何找到方法可用的所有标志?例如,tagd_with具有:on,:any,:match_all,...,我如何列出所有这些?
Also, a side question is, how do you find all the flags available to a method? For example, tagged_with has :on, :any, :match_all, ..., how do i list all of them ?
谢谢大家的帮助!
推荐答案
好的,我找到了问题所在.感谢aurelian向我指出了act_as_taggable_on的来源. 原来,截至3月18日,在github上已修复了:any覆盖:on的问题.而且rubygem.org上的宝石还没有包含此修复程序.
All right, I found the where the problem is. Thanks to aurelian for pointing me to the source of acts_as_taggable_on. It turned out that the fix for :any overwriting :on issue was fixed as of March 18 on github master. And the gem from rubygem.org doesn't include this fix yet.
因此,不要使用rubygem.org构建我的应用程序:
gem 'acts_as_taggable_on'
So instead of building my app from rubygem.org using:
gem 'acts_as_taggable_on'
我只是将其直接指向git源:
gem 'acts_as_taggable_on', :git => 'git://github.com/mbleigh/acts-as-taggable-on.git'
I just point it straight to the git source:
gem 'acts_as_taggable_on', :git => 'git://github.com/mbleigh/acts-as-taggable-on.git'
这篇关于:any标志是否会覆盖acts_as_taggable_on的agged_with中的:on(上下文)标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!