-
-
Notifications
You must be signed in to change notification settings - Fork 807
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
Would an ActsAsTaggableOn extension for Ransack be possible? #135
Comments
👍 |
Is there any walkaround for this? I need to filter out by skills and moods and interests all done with acts_as_taggable _on.... |
It seems to be a dead end : http://stackoverflow.com/questions/19421508/ransack-and-acts-as-taggable-on-issues |
I need to make some hack to deal with it. I Hope i could be improved. In my controller (I have inherited resources) : def collection
ransack_params = params[:q]
# Hack to delete params can't be used by ransack
tag_search = ransack_params["tag_search"].split(",") if ransack_params.present? && ransack_params["tag_search"].present?
ransack_params.delete("tag_search") if ransack_params.present?
select_time_tables = tag_search ? referential.time_tables.tagged_with(tag_search, :any => true) : referential.time_tables
@q = select_time_tables.search(ransack_params)
@time_tables ||= @q.result(:distinct => true).order(:comment).paginate(:page => params[:page])
end In my model : def self.ransackable_attributes auth_object = nil
(column_names + ['tag_search']) + _ransackers.keys
end |
You can add it by association, f.e.:
It works for me I think it is the better way to do it. |
The answer from @norato above worked well, but I found I didn't need to add anything to the model, just the view. This worked for my recipes page (
|
@dominiceden I just created this constant in model, the functionality is the same. I did it 'cause we use a lot of custom searches in this page so we prefered to create as constants :-) |
The problem with @norato solution is that you have the following tags: EDIT: I've found a solution - use |
@metalelf0 Any chance to document your findings in the Wiki? |
Sure. Here's the link: https://github.com/activerecord-hackery/ransack/wiki/How-to-search-on-ActsAsTaggableOn-fields. Let me know if it's ok. :) |
@metalelf0 I've tried the wiki link and it throws "undefined method" this is my case: in my model:
in my view:
I'm using ruby 2.2.4, rails 4.2.6 and ransack 1.8.3 |
@sutherland007 if you don't mind uploading your app on github I'll download it and give it a try. Feel free to contact me on gitter. |
@metalelf0 this is the app feel free to test it. |
@sutherland007 In your scenario the field name should be |
@metalelf0 Thanks, i think you need to update your guide using this little experience with my app. So I must say that |
Hi,
we just started using Ransack and I have to say, I really, really love it's API!
We are also using ActsAsTaggableOn (https://github.com/mbleigh/acts-as-taggable-on) and I was wondering what it would take to write something like a Ransack "extension" or so to integrate with ActsAsTaggableOn?
Any assessment on whether and how this would be possible, would be very appreciated.
The text was updated successfully, but these errors were encountered: