Module: ActsAsTaggableOn::Taggable
- Defined in:
- lib/acts_as_taggable_on_padrino/taggable.rb,
lib/acts_as_taggable_on_padrino/taggable/core.rb,
lib/acts_as_taggable_on_padrino/taggable/cache.rb,
lib/acts_as_taggable_on_padrino/taggable/related.rb,
lib/acts_as_taggable_on_padrino/taggable/tag_list.rb,
lib/acts_as_taggable_on_padrino/taggable/ownership.rb,
lib/acts_as_taggable_on_padrino/taggable/collection.rb
Defined Under Namespace
Modules: Cache, Collection, Core, Ownership, Related Classes: TagList
Instance Method Summary collapse
-
#acts_as_taggable(opts = {}) ⇒ Object
This is an alias for calling
acts_as_taggable_on_padrino :tags
. -
#acts_as_taggable_on(*tag_types) ⇒ Object
Make a model taggable on specified contexts.
- #taggable? ⇒ Boolean
Instance Method Details
#acts_as_taggable(opts = {}) ⇒ Object
This is an alias for calling acts_as_taggable_on_padrino :tags
.
Example:
class Book < ActiveRecord::Base
acts_as_taggable
end
14 15 16 |
# File 'lib/acts_as_taggable_on_padrino/taggable.rb', line 14 def acts_as_taggable(opts = {}) acts_as_taggable_on :tags, opts end |
#acts_as_taggable_on(*tag_types) ⇒ Object
Make a model taggable on specified contexts.
Example:
class User < ActiveRecord::Base
acts_as_taggable_on_padrino :languages, :skills
end
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/acts_as_taggable_on_padrino/taggable.rb', line 27 def acts_as_taggable_on(*tag_types) opts = tag_types. opts.assert_valid_keys :tag, :tagging tag_types = tag_types.to_a.flatten.compact.map {|type| type.to_sym } if taggable? write_inheritable_attribute(:tag_types, (self.tag_types + tag_types).uniq) else opts.reverse_merge!(:tag => 'Tag', :tagging => 'Tagging') tag_class_name = opts[:tag] tagging_class_name = opts[:tagging] tag = tag_class_name.constantize tagging = tagging_class_name.constantize write_inheritable_attribute(:tag_types, tag_types) write_inheritable_attribute(:acts_as_taggable_on_tag_model, tag) write_inheritable_attribute(:acts_as_taggable_on_tagging_model, tagging) class_inheritable_reader(:tag_types, :acts_as_taggable_on_tagging_model, :acts_as_taggable_on_tag_model) class_eval do has_many :taggings, :as => :taggable, :dependent => :destroy, :include => :tag, :class_name => tagging_class_name has_many :base_tags, :through => :taggings, :source => :tag, :class_name => tag_class_name def self.taggable? true end include ActsAsTaggableOn::Taggable::Core include ActsAsTaggableOn::Taggable::Collection include ActsAsTaggableOn::Taggable::Cache include ActsAsTaggableOn::Taggable::Ownership include ActsAsTaggableOn::Taggable::Related end end end |
#taggable? ⇒ Boolean
3 4 5 |
# File 'lib/acts_as_taggable_on_padrino/taggable.rb', line 3 def taggable? false end |