class Tag
This model doesn't actually create relationships between objects.
It really just defines what tags you are able to use. So before adding a tag to an object, you must first create a new Tag with the desired values if one doesn't already exist.
Constants
- TYPES
-
Categories tags are for broad categories like 'music', 'technology', but
-
Object tags should be specific to one object. And the name should be clear what that object is.
Each tag should be owned by only one object, but other objects can subscribe to things published with that tag. It should be in the form of 'slug-modelname'. ex: Music Department would own the tag 'music-department'
-
Topic tags are more specific than category tags. Like 'saxophone',
-
Public Class Methods
create_from_object(object, current_user: nil, class_slug: nil, object_slug: nil)
click to toggle source
Creates an object tag from a given object. Returns the created tag or nil (if invalid).
Accepts two optional parameters:
* object_slug: nil # This defaults to the object's slug if one exists. * class_slug: nil # For overwriting the class name portion of the tag. Ex: 'music-dept' instead of 'music-department' Tag.create_from_object(@department) Tag.create_from_object(@department, class_slug: 'dept', object_slug: 'music')
# File lib/buweb/tag.rb, line 53 def self.create_from_object(object, current_user: nil, class_slug: nil, object_slug: nil) class_slug ||= object.class.to_s.underscore # If object does not respond to slug and no `object_slug` is given as a parameter, this will not validate object_slug ||= object.slug if object.respond_to?(:slug) tag = Tag.new(type: 'object', tag: "#{object_slug}-#{class_slug}".downcase.parameterize.dasherize, object_type: object.class.to_s, modifier: current_user) if tag.save tag else nil end end
Public Instance Methods
to_s()
click to toggle source
# File lib/buweb/tag.rb, line 40 def to_s tag end