Class: Tag

Inherits:
ApplicationRecord show all
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

Instance Method Details

#before_createObject

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

#labelObject



23
24
25
# File 'app/models/tag.rb', line 23

def label
  @label ||= name.tr(' '.freeze, '-'.freeze)
end

#to_sObject



27
28
29
# File 'app/models/tag.rb', line 27

def to_s
  name
end