Class: WorldDB::Models::Tag
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- WorldDB::Models::Tag
- Defined in:
- lib/worlddb/models/tag.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#key ⇒ Object
fix/todo: improve regex use [a-z] | [a-z][a-z0-9_ ]+[a-z0-9] to only allow spaces and underscore inbetween; do not allow digit as first char.
- #on_before_save ⇒ Object
Class Method Details
.by_key ⇒ Object
23 24 25 |
# File 'lib/worlddb/models/tag.rb', line 23 def self.by_key self.order( 'key desc' ) end |
.by_title ⇒ Object
27 28 29 |
# File 'lib/worlddb/models/tag.rb', line 27 def self.by_title self.order( 'title desc' ) end |
Instance Method Details
#key ⇒ Object
fix/todo: improve regex use [a-z] | [a-z][a-z0-9_ ]+[a-z0-9] to 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-z0-9_ ]{2,}$/, :message => 'expected two or more lowercase letters a-z or 0-9 digits or space or underscore' } |
#on_before_save ⇒ Object
18 19 20 21 |
# File 'lib/worlddb/models/tag.rb', line 18 def on_before_save # replace space with underscore e.g. north america becomes north_america and so on self.slug = key.gsub( ' ', '_' ) end |