Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Category < ActiveRecord::Base
- validates_presence_of :title
- private
- def validate
- errors.add(:description, "is too short") if (description.size < 200)
- end
- end
- class Category < ActiveRecord::Base
- validates_presence_of :title
- validate :description_length
- def description_length
- errors.add(:description, "is too short") if (description.size < 200)
- end
- end
- class TitleValidator < ActiveModel::EachValidator
- Titles = ['Mr.', 'Mrs.', 'Dr.']
- def validate_each(record, attribute, value)
- unless Titles.include?(value)
- record.errors[attribute] << 'must be a valid title'
- end
- end
- end
- class Person
- include ActiveModel::Validations
- attr_accessor :title
- validates :title, :presence => true, :title => true
- end
- # Or for Active Record
- class Person < ActiveRecord::Base
- validates :title, :presence => true, :title => true
- end
Add Comment
Please, Sign In to add comment