Sha256: 127e2b78ada8aef0b76e1007a16dd41f5ce9d089c2da3eddb3a2dbd6052dcec2
Contents?: true
Size: 812 Bytes
Versions: 7
Compression:
Stored size: 812 Bytes
Contents
class ValidateComments < UseCase::Validator target :comments, in: :post validates_presence_of :title, message: "can't be blank!" validates_format_of :email, with: /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i, message: "invalid format!" validates_length_of :title, minimum: 6, allow_nil: true validate :custom_validation1, :custom_validation2 protected ######################### PROTECTED ############################ def custom_validation1(comment) if ['force_error1', 'force_error2'].include?(comment.title) comment.errors.add(:title, 'custom_validation1') return false end true end def custom_validation2(comment) if comment.email == "force_error@gmail.com" comment.errors.add(:email, 'custom_validation2') return false end true end end
Version data entries
7 entries across 7 versions & 1 rubygems