aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib
diff options
context:
space:
mode:
authorMartin Larochelle <martin.larochelle@shopify.com>2018-05-22 17:20:14 -0400
committerMartin Larochelle <martin.larochelle@shopify.com>2018-06-05 13:25:24 -0400
commit32513c4b356ed8b87b2c9caec6354b4b21cfc692 (patch)
tree3222d572500a931eefc425312bce82cac13f83bc /activemodel/lib
parent7d09874a71ecceb929a99f914b703adc16d80e83 (diff)
downloadrails-32513c4b356ed8b87b2c9caec6354b4b21cfc692.tar.gz
rails-32513c4b356ed8b87b2c9caec6354b4b21cfc692.tar.bz2
rails-32513c4b356ed8b87b2c9caec6354b4b21cfc692.zip
Add global config for config.active_model.i18n_full_message
Diffstat (limited to 'activemodel/lib')
-rw-r--r--activemodel/lib/active_model/errors.rb7
-rw-r--r--activemodel/lib/active_model/railtie.rb6
2 files changed, 12 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index e813629855..d583d48b54 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -62,6 +62,11 @@ module ActiveModel
CALLBACKS_OPTIONS = [:if, :unless, :on, :allow_nil, :allow_blank, :strict]
MESSAGE_OPTIONS = [:message]
+ class << self
+ attr_accessor :i18n_full_message # :nodoc:
+ end
+ self.i18n_full_message = false
+
attr_reader :messages, :details
# Pass in the instance of the object that is using the errors object.
@@ -375,7 +380,7 @@ module ActiveModel
def full_message(attribute, message)
return message if attribute == :base
- if @base.class.respond_to?(:i18n_scope)
+ if self.class.i18n_full_message && @base.class.respond_to?(:i18n_scope)
parts = attribute.to_s.split(".")
attribute_name = parts.pop
namespace = parts.join("/") unless parts.empty?
diff --git a/activemodel/lib/active_model/railtie.rb b/activemodel/lib/active_model/railtie.rb
index a9cdabba00..0ed70bd473 100644
--- a/activemodel/lib/active_model/railtie.rb
+++ b/activemodel/lib/active_model/railtie.rb
@@ -7,8 +7,14 @@ module ActiveModel
class Railtie < Rails::Railtie # :nodoc:
config.eager_load_namespaces << ActiveModel
+ config.active_model = ActiveSupport::OrderedOptions.new
+
initializer "active_model.secure_password" do
ActiveModel::SecurePassword.min_cost = Rails.env.test?
end
+
+ initializer "active_model.i18n_full_message" do
+ ActiveModel::Errors.i18n_full_message = config.active_model.delete(:i18n_full_message) || false
+ end
end
end