diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2016-04-06 01:01:50 -0300 |
---|---|---|
committer | Rafael França <rafaelmfranca@gmail.com> | 2016-04-06 01:01:50 -0300 |
commit | 659b104a006a346644fcbc4c6a40e8b717947429 (patch) | |
tree | 8b4a1083569c40ab8407236692707c052014e528 /guides/source | |
parent | 54ce28017c532833f29a5df7512e34c402ce9e78 (diff) | |
parent | 7f1fc1ee093732de7da9427370ff4858790a3684 (diff) | |
download | rails-659b104a006a346644fcbc4c6a40e8b717947429.tar.gz rails-659b104a006a346644fcbc4c6a40e8b717947429.tar.bz2 rails-659b104a006a346644fcbc4c6a40e8b717947429.zip |
Merge pull request #24444 from prathamesh-sonpatki/update-message-proc-documentation
Update example of passing a proc to `:message` option for validating records [ci skip]
Diffstat (limited to 'guides/source')
-rw-r--r-- | guides/source/active_record_validations.md | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/guides/source/active_record_validations.md b/guides/source/active_record_validations.md index bd16ccad12..1cf4abce10 100644 --- a/guides/source/active_record_validations.md +++ b/guides/source/active_record_validations.md @@ -785,7 +785,7 @@ A `String` `:message` value can optionally contain any/all of `%{value}`, `%{attribute}`, and `%{model}` which will be dynamically replaced when validation fails. -A `Proc` `:message` value is given two arguments: a message key for i18n, and +A `Proc` `:message` value is given two arguments: the object being validated, and a hash with `:model`, `:attribute`, and `:value` key-value pairs. ```ruby @@ -801,10 +801,10 @@ class Person < ApplicationRecord # Proc validates :username, uniqueness: { - # key = "activerecord.errors.models.person.attributes.username.taken" + # object = person object being validated # data = { model: "Person", attribute: "Username", value: <username> } - message: ->(key, data) do - "#{data[:value]} taken! Try again #{Time.zone.tomorrow}" + message: ->(object, data) do + "Hey #{object.name}!, #{data[:value]} is taken already! Try again #{Time.zone.tomorrow}" end } end |