Super lightweight alternative to all the other tagging gems out there.
Add this line to your application's Gemfile:
gem 'tagging_along'
And then execute:
$ bundle
Or install it yourself as:
$ gem install tagging_along
Include the gem in the model you want to use it with:
class User
include TaggingAlong
end
and define the attributes that are taggable inside the class:
class User
include TaggingAlong
attr_accessor :cars
is_taggable_on :cars
end
Instances of your class will now have taggable attributes. For example:
user = User.new
user.cars = 'Audi,BMW'
user.cars_tags
# => ['Audi', 'BMW']
user.cars_list
# => 'Audi, BMW'
You can also specify a custom separator:
class User
include TaggingAlong
attr_accessor :cars
is_taggable_on :cars, separator: ':'
end
which will play out like this:
user = User.new
user.cars = 'Audi:BMW'
user.cars_tags
# => ['Audi', 'BMW']
user.cars_list
# => 'Audi: BMW'
You can define multiple taggable attributes in one go:
class User
include TaggingAlong
attr_accessor :cars, :qualifications
is_taggable_on :cars, :qualifications
end
That's it!
If you use RSpec, you can check if your model is taggable like this:
User.should be_taggable_on :cars
- Fork it ( https://github.com/CrowdCurity/tagging_along/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request