class Tag::Validator
Public Instance Methods
validate(record)
click to toggle source
# File lib/ecrire/app/models/tag.rb, line 3 def validate(record) validate_presence! record validate_uniqueness! record end
validate_presence!(record)
click to toggle source
# File lib/ecrire/app/models/tag.rb, line 8 def validate_presence!(record) if record.name.blank? msg = "Your tag can't be blank." record.errors['name'] << msg elsif record.name.length < 1 msg = "Your tag needs to be at least 1 character long." record.errors['name'] << msg end end
validate_uniqueness!(record)
click to toggle source
# File lib/ecrire/app/models/tag.rb, line 18 def validate_uniqueness!(record) tag = Tag.where('tags.name = ?', record.name).first unless tag.nil? msg = "You already have a tag with this name: #{tag.name}" record.errors['uniqueness'] << msg return end end