Sha256: dec33817358f3172c480637976c03e64f3845ebf286f887dc1e850c49a8d69e7
Contents?: true
Size: 936 Bytes
Versions: 3
Compression:
Stored size: 936 Bytes
Contents
require 'bundler' Bundler.setup(:default, :development) require 'mongoid-tag-collectible' Mongoid.configure do |config| config.connect_to('mongoid_tag_collectible_example') end class Thing include Mongoid::Document include Mongoid::TagCollectible::Tagged before_validation :downcase_tags private def downcase_tags tags.map(&:downcase) if tags end end Thing.create!(tags: %w(funny red)) Thing.create!(tags: %w(funny yellow)) funny_tag = ThingTag.where(name: 'funny').first puts funny_tag.name # funny puts funny_tag.count # 2 p funny_tag.tagged.to_a # thing1 and thing2 # rename a tag ThingTag.find('funny').update_attributes!(name: 'sad') p Thing.first.tags # [ 'red', 'sad' ] # delete a tag ThingTag.find('red').destroy p Thing.first.tags # [ 'sad' ] if Mongoid::TagCollectible.mongoid3? || Mongoid::TagCollectible.mongoid4? Mongoid.default_session.drop else Mongoid::Clients.default.database.drop end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
mongoid-tag-collectible-0.2.2 | examples/readme.rb |
mongoid-tag-collectible-0.2.1 | examples/readme.rb |
mongoid-tag-collectible-0.2.0 | examples/readme.rb |