tmiyamon / acts-as-taggable-array-on

A simple and high performance tagging gem for Rails using PostgreSQL array.
MIT License
125 stars 26 forks source link

Finder methods, multiple parameters #2

Closed miletbaker closed 3 years ago

miletbaker commented 10 years ago

@tmiyamon firstly thanks for the excellent gem, I'm seriously considering pulling acts_as_taggable_on as this is more suited and performs faster for our needs.

One question is in regards to the scopes that get added by acts_as_taggable_array_on. You have designed it to expect multiple parameters when searching for records that match with_any or without_any etc. I'm not sure of a time when you would search for records this way unless you are on the console as most input data would be in a string of tags to search. For example from a search form the user would comma separate the tags to search for.

As you have specified *tags on the scope parameters, so with multiple tags you need to call the method with multiple parameters, which is fine in the console, i.e.:

User.with_all_tags "awesome", "slick"

But most of the time I would have though you will have your list of tags to search on in an array or string. So for example if you want to search with an array of tags you need to call this as follows:

User.with_all_tags *["awesome", "slick"]

Note: the * before the array

If you want to search with a string of comma separated tags, you would need to call

User.with_all_tags *("awesome, slick").join(",")collect(&:strip))

Am I missing something, and/or it may be worth documenting this? Also it might be better to move this / change the way these are called in the scope, though I guess any change like this would break any existing usage?

Just some thoughts anyway, I thought I would start the discussion and for now I'll use the workarounds above.

Jon

tmiyamon commented 10 years ago

@miletbaker Thank you for your comment! According to your suggestion, it looks better the newly defined scopes expect single parameter since it can support both cases of array and string.

Ok, I will try to update the gem with this way. please be patient..

By the way, the bellow one is what you want to show in the third example, right?

User.with_all_tags *("awesome, slick").split(",").collect(&:strip)
miletbaker commented 10 years ago

Yes you are correct thanks.

tmiyamon commented 10 years ago

@miletbaker I updated to 0.3.0. Please try it out.

skatkov commented 3 years ago

Closing. No activity.