From fc0358ae16d5631dd1d996b2cf95a8987f9d0c8d Mon Sep 17 00:00:00 2001
From: Iain Hecker <github@iain.nl>
Date: Sat, 16 Aug 2008 21:45:23 +0200
Subject: Added :value as interpolation variable available to error messages

---
 activerecord/lib/active_record/validations.rb | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

(limited to 'activerecord/lib')

diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb
index 040681a09c..a442d008a9 100644
--- a/activerecord/lib/active_record/validations.rb
+++ b/activerecord/lib/active_record/validations.rb
@@ -92,17 +92,19 @@ module ActiveRecord
           :"custom.#{klass.name.underscore}.#{message}" ]
       end
       
-      defaults << options[:default] if options[:default]
-      defaults.flatten! << message
+      defaults << options.delete(:default)
+      defaults = defaults.compact.flatten << message
 
       model_name = @base.class.name
       key = defaults.shift
-
-      options.merge!({ 
-          :default => defaults,
-          :model => @base.class.human_name,
-          :attribute => @base.class.human_attribute_name(attribute.to_s),
-          :scope => [:activerecord, :errors, :messages] })
+      value = @base.send(attribute) if @base.respond_to?(attribute)
+
+      options = { :default => defaults,
+        :model => @base.class.human_name,
+        :attribute => @base.class.human_attribute_name(attribute.to_s),
+        :value => value,
+        :scope => [:activerecord, :errors, :messages]
+      }.merge(options)
 
       I18n.translate(key, options)
     end
-- 
cgit v1.2.3