diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-12-05 15:09:43 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-12-05 15:09:43 +0300 |
commit | 519d1054bcd894f514cc5c607a42be336d05df48 (patch) | |
tree | 3c3e78f47ab9ea95d0d2ff08aeeae5a6b3f405ea /app/validators/duration_validator.rb | |
parent | c6c21dd4566899ca85fa3754833dfd0c70f1768a (diff) |
Add custom validation message for chronic duration attribute
Diffstat (limited to 'app/validators/duration_validator.rb')
-rw-r--r-- | app/validators/duration_validator.rb | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/app/validators/duration_validator.rb b/app/validators/duration_validator.rb index 811828169ca..defd28d7d3b 100644 --- a/app/validators/duration_validator.rb +++ b/app/validators/duration_validator.rb @@ -14,6 +14,10 @@ class DurationValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) ChronicDuration.parse(value) rescue ChronicDuration::DurationParseError - record.errors.add(attribute, "is not a correct duration") + if options[:message] + record.errors.add(:base, options[:message]) + else + record.errors.add(attribute, "is not a correct duration") + end end end |