Class: WorldDB::Models::Tag

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/worlddb/models/tag.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.by_keyObject



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

def self.by_key
  self.order( 'key desc' )
end

.by_titleObject



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

def self.by_title
  self.order( 'title desc' )
end

Instance Method Details

#keyObject

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_saveObject



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