我正在尝试将ransack
gem 与acts_as_taggable
. 我有一个以默认方式配置并具有属性的简单Job
模型。acts_as_taggable
tag_list
当我运行时:
Job.ransack("tags_name_in"=>["eum", "sint"]).result.to_sql
它按预期生成 SQL(这很好):
"SELECT \"jobs\".* FROM \"jobs\" LEFT OUTER JOIN \"taggings\" ON \"taggings\".\"taggable_id\" = \"jobs\".\"id\" AND \"taggings\".\"context\" = 'tags' AND \"taggings\".\"taggable_type\" = 'Job' LEFT OUTER JOIN \"tags\" ON \"tags\".\"id\" = \"taggings\".\"tag_id\" WHERE \"tags\".\"name\" IN ('eum', 'sint')"
但是当我试图通过使用排除时:
Job.ransack("tags_name_not_in"=>["eum", "sint"]).result.to_sql
它抛出 exaptation:
NoMethodError: undefined method `left' for #<ActiveRecord::Relation::QueryAttribute:0x007f851ea6bcd8>
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/ransack-1.8.2/lib/ransack/adapters/active_record/context.rb:190:in `block in build_correlated_subquery'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/ransack-1.8.2/lib/ransack/adapters/active_record/context.rb:189:in `each'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/ransack-1.8.2/lib/ransack/adapters/active_record/context.rb:189:in `build_correlated_subquery'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/ransack-1.8.2/lib/ransack/adapters/active_record/ransack/nodes/condition.rb:9:in `block in arel_predicate'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/ransack-1.8.2/lib/ransack/adapters/active_record/ransack/nodes/condition.rb:6:in `map'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/ransack-1.8.2/lib/ransack/adapters/active_record/ransack/nodes/condition.rb:6:in `arel_predicate'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/ransack-1.8.2/lib/ransack/visitor.rb:17:in `visit_Ransack_Nodes_Condition'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/ransack-1.8.2/lib/ransack/visitor.rb:52:in `visit'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/ransack-1.8.2/lib/ransack/visitor.rb:5:in `accept'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/ransack-1.8.2/lib/ransack/adapters/active_record/ransack/visitor.rb:4:in `block in visit_and'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/ransack-1.8.2/lib/ransack/adapters/active_record/ransack/visitor.rb:4:in `map'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/ransack-1.8.2/lib/ransack/adapters/active_record/ransack/visitor.rb:4:in `visit_and'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/ransack-1.8.2/lib/ransack/visitor.rb:24:in `visit_Ransack_Nodes_Grouping'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/ransack-1.8.2/lib/ransack/visitor.rb:52:in `visit'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/ransack-1.8.2/lib/ransack/visitor.rb:5:in `accept'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/ransack-1.8.2/lib/ransack/adapters/active_record/context.rb:37:in `evaluate'
... 12 levels...
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:287:in `load'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:287:in `block in load'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:287:in `load'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/spring-2.0.1/lib/spring/commands/rails.rb:6:in `call'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/spring-2.0.1/lib/spring/command_wrapper.rb:38:in `call'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/spring-2.0.1/lib/spring/application.rb:191:in `block in serve'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/spring-2.0.1/lib/spring/application.rb:161:in `fork'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/spring-2.0.1/lib/spring/application.rb:161:in `serve'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/spring-2.0.1/lib/spring/application.rb:131:in `block in run'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/spring-2.0.1/lib/spring/application.rb:125:in `loop'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/spring-2.0.1/lib/spring/application.rb:125:in `run'
from /Users/sashar/.rvm/gems/ruby-2.2.5/gems/spring-2.0.1/lib/spring/application/boot.rb:19:in `<top (required)>'
from /Users/sashar/.rvm/rubies/ruby-2.2.5/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/sashar/.rvm/rubies/ruby-2.2.5/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'
有任何想法吗?