aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/validations.rb
diff options
context:
space:
mode:
authorSven Fuchs <svenfuchs@artweb-design.de>2008-06-21 17:50:37 +0200
committerSven Fuchs <svenfuchs@artweb-design.de>2008-06-21 17:50:37 +0200
commit8bfdabbd8b5137f91d8bcddc8c3d18961c8e316b (patch)
treeb13a11fd59dc3437365a7ce43c608b2afccaef0b /activerecord/lib/active_record/validations.rb
parent428aa24d24032d382dc3d9ccf131e0c874043dbd (diff)
downloadrails-8bfdabbd8b5137f91d8bcddc8c3d18961c8e316b.tar.gz
rails-8bfdabbd8b5137f91d8bcddc8c3d18961c8e316b.tar.bz2
rails-8bfdabbd8b5137f91d8bcddc8c3d18961c8e316b.zip
incorporate #translate usage with several default keys
(use first default key that resolves to a translation). this might, depending on the backend implementation save some expensive lookups (like db lookups)
Diffstat (limited to 'activerecord/lib/active_record/validations.rb')
-rwxr-xr-xactiverecord/lib/active_record/validations.rb19
1 files changed, 16 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb
index bcb204f1ba..49d3c59ca7 100755
--- a/activerecord/lib/active_record/validations.rb
+++ b/activerecord/lib/active_record/validations.rb
@@ -66,9 +66,11 @@ module ActiveRecord
end
def generate_message(attr, key, options = {})
- scope = [:active_record, :error_messages]
- key.t(options.merge(:scope => scope + [:custom, @base.class.name.downcase, attr])) ||
- key.t(options.merge(:scope => scope))
+ msgs = base_classes(@base.class).map{|klass| :"custom.#{klass.name.underscore}.#{attr}.#{key}"}
+ msgs << options[:default] if options[:default]
+ msgs << key
+
+ I18n.t options.merge(:default => msgs, :scope => [:active_record, :error_messages])
end
# Returns true if the specified +attribute+ has errors associated with it.
@@ -217,6 +219,17 @@ module ActiveRecord
full_messages.each { |msg| e.error(msg) }
end
end
+
+ protected
+
+ # TODO maybe this should be on ActiveRecord::Base, maybe #self_and_descendents_from_active_record
+ def base_classes(klass)
+ classes = [klass]
+ while klass != klass.base_class
+ classes << klass = klass.superclass
+ end
+ classes
+ end
end