这似乎是 Rails 的一个特性。见:https ://gist.github.com/rails/rails/issues/6489
一个可能的解决方法是通过将类似这样的内容放置到 application.rb 来覆盖罪魁祸首:
module ActiveModel
module Translation
def human_attribute_name(attribute, options = {})
defaults = []
parts = attribute.to_s.split(".", 2)
attribute = parts.pop
namespace = parts.pop
if namespace
lookup_ancestors.each do |klass|
defaults << :"#{self.i18n_scope}.attributes.#{klass.model_name.i18n_key}/#{namespace}.#{attribute}"
end
defaults << :"#{self.i18n_scope}.attributes.#{namespace}.#{attribute}"
else
lookup_ancestors.each do |klass|
defaults << :"#{self.i18n_scope}.attributes.#{klass.model_name.i18n_key}.#{attribute}"
end
end
defaults << :"attributes.#{attribute}"
defaults << options.delete(:default) if options[:default]
defaults << "MISSING TRANSLATION"+defaults.to_yaml # defaults << attribute.humanize
options.reverse_merge! :count => 1, :default => defaults
I18n.translate(defaults.shift, options)
end
end
end