Class: Tag
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Tag
- Defined in:
- app/models/tag.rb
Constant Summary collapse
- DELIMITER =
Controls how to split and join tagnames from strings. You may need to change the validates_format_of parameters if you change this.
",".freeze
- JOIN_DELIMITER =
", ".freeze
Instance Method Summary collapse
-
#before_create ⇒ Object
Callback to strip extra spaces from the tagname before saving it.
- #label ⇒ Object
- #to_s ⇒ Object
Instance Method Details
#before_create ⇒ Object
Callback to strip extra spaces from the tagname before saving it. If you allow tags to be renamed later, you might want to use the before_save callback instead.
19 20 21 |
# File 'app/models/tag.rb', line 19 def before_create self.name = name.downcase.strip.squeeze(' '.freeze) end |
#label ⇒ Object
23 24 25 |
# File 'app/models/tag.rb', line 23 def label @label ||= name.tr(' '.freeze, '-'.freeze) end |
#to_s ⇒ Object
27 28 29 |
# File 'app/models/tag.rb', line 27 def to_s name end |