Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using ransack with acts_as_taggable to exclude some tags. #788

Closed
sasharevzin opened this issue May 15, 2017 · 5 comments
Closed

Using ransack with acts_as_taggable to exclude some tags. #788

sasharevzin opened this issue May 15, 2017 · 5 comments

Comments

@sasharevzin
Copy link
Contributor

sasharevzin commented May 15, 2017

Hi guys,

I'm trying to use ransack gem with acts_as_taggable. I have a simple Job model that configured acts_as_taggable in a default way and has tag_list property.

When I run:

Job.ransack("tags_name_in"=>["eum", "sint"]).result.to_sql

It generates SQL as expected (which is good):

"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')"

But when I'm trying to exclude by using:

Job.ransack("tags_name_not_in"=>["eum", "sint"]).result.to_sql

It throws 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>'

Any ideas?

@scarroll32
Copy link
Member

This issue appears more to be a HOW-TO issue rather than a bug in Ransack. We are in the process of cleaning up the Ransack gem and repo. If this issue is still relevant could you please ask it on StackOverflow?

If you think it is an issue with Ransack, please provide a repo with the issue and / or a pull request with failing tests. If you don't know how to do this, indicate it in the issue and we will look into it eventually.

Thank you

https://github.com/activerecord-hackery/ransack/blob/master/CONTRIBUTING.md

#794

@sasharevzin
Copy link
Contributor Author

Thanks, @seanfcarroll. I still think this is an issue and I already asked the question two weeks ago: https://stackoverflow.com/questions/44074071/exclude-from-array-doesnt-work-as-expected

I'll create PR.

Thanks again!

@scarroll32
Copy link
Member

Fantastic! Thank you

@scarroll32
Copy link
Member

Hi @sasharevzin thanks for your contributions. Did you make any progress on this? I'm dubious about adding a dependency to acts-as-taggable-on to Ransack, I'd be more inclined to separate it out if possible.

I'd like to close this unless you have a PR or branch in progress.

@scarroll32
Copy link
Member

Closed due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants