aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib
diff options
context:
space:
mode:
authorSamuel Elliott <sam@lenary.co.uk>2010-01-17 12:15:52 +0100
committerJosé Valim <jose.valim@gmail.com>2010-01-17 14:40:10 +0100
commit31ea83eb898786f853bd7ce7075986fa120f949d (patch)
treef2336037a93c72680db7f9e8030939b85f73891b /activemodel/lib
parentc0d31ca41b2f019d3bf940ac79f104c412b115bf (diff)
downloadrails-31ea83eb898786f853bd7ce7075986fa120f949d.tar.gz
rails-31ea83eb898786f853bd7ce7075986fa120f949d.tar.bz2
rails-31ea83eb898786f853bd7ce7075986fa120f949d.zip
Adding Proc support to validation messages so that they can become a little more dynamic, allowing for customisations during the request [#3514 status:resolved].
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activemodel/lib')
-rw-r--r--activemodel/lib/active_model/errors.rb2
1 files changed, 2 insertions, 0 deletions
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 <tt>on(attribute)</tt>.
# 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