From afd0c06dfa8d3e04e85f9f0ea65c9beb376cb79f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 17 Jan 2010 09:57:16 +0100 Subject: Validates needs hash slice. --- activemodel/lib/active_model/validations/validates.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activemodel/lib/active_model') diff --git a/activemodel/lib/active_model/validations/validates.rb b/activemodel/lib/active_model/validations/validates.rb index 4c82a993ae..90b244228a 100644 --- a/activemodel/lib/active_model/validations/validates.rb +++ b/activemodel/lib/active_model/validations/validates.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/hash/slice' + module ActiveModel module Validations module ClassMethods -- cgit v1.2.3 From 31ea83eb898786f853bd7ce7075986fa120f949d Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Sun, 17 Jan 2010 12:15:52 +0100 Subject: Adding Proc support to validation messages so that they can become a little more dynamic, allowing for customisations during the request [#3514 status:resolved]. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activemodel/lib/active_model/errors.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activemodel/lib/active_model') diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 0b6c75c46e..2e5bcab070 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -60,9 +60,11 @@ module ActiveModel # error can be added to the same +attribute+ in which case an array will be returned on a call to on(attribute). # If no +messsage+ is supplied, :invalid is assumed. # If +message+ is a Symbol, it will be translated, using the appropriate scope (see translate_error). + # If +message+ is a Proc, it will be called, allowing for things like Time.now to be used within an error def add(attribute, message = nil, options = {}) message ||= :invalid message = generate_message(attribute, message, options) if message.is_a?(Symbol) + message = message.call if message.is_a?(Proc) self[attribute] << message end -- cgit v1.2.3