Class: WorldDb::Models::Tag
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- WorldDb::Models::Tag
- Defined in:
- lib/worlddb/models/tag.rb
Instance Method Summary collapse
-
#key ⇒ Object
nb: only allow spaces and underscore inbetween; do not allow digit as first char.
- #on_before_save ⇒ Object
Instance Method Details
#key ⇒ Object
nb: only allow spaces and underscore inbetween; do not allow digit as first char
14 |
# File 'lib/worlddb/models/tag.rb', line 14 validates :key, :format => { :with => /^[a-z]$|^[a-z][a-z0-9_ ]*[a-z0-9]$/, :message => 'expected one or more lowercase letters a-z or 0-9 digits or space or underscore' } |
#on_before_save ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/worlddb/models/tag.rb', line 22 def on_before_save # replace space with underscore e.g. north america becomes north_america and so on self.slug = key.gsub( ' ', '_' ) ## if title is empty auto fill w/ key self.title = key if title.blank? end |