From 7f1fc1ee093732de7da9427370ff4858790a3684 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Wed, 6 Apr 2016 09:29:01 +0530 Subject: Update example of passing a proc to `:message` option for validating records [ci skip] - This change is made as the behavior for `:message` proc was changed in https://github.com/rails/rails/pull/24119. - Also check https://github.com/rails/rails/pull/24431#issuecomment-206106790 for reference. --- guides/source/active_record_validations.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'guides/source') 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: } - 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 -- cgit v1.2.3