diff --git a/activerecord/lib/active_record/associations/nested_error.rb b/activerecord/lib/active_record/associations/nested_error.rb index 3bdca88765f79..794118dc2e1c9 100644 --- a/activerecord/lib/active_record/associations/nested_error.rb +++ b/activerecord/lib/active_record/associations/nested_error.rb @@ -18,15 +18,11 @@ def initialize(association, inner_error) def compute_attribute(inner_error) association_name = association.reflection.name - attribute = - if index_errors_setting && index - "#{association_name}[#{index}]" - else - association_name - end - - attribute = :"#{attribute}.#{inner_error.attribute}" if inner_error.attribute != :base - attribute.to_sym + if index_errors_setting && index + "#{association_name}[#{index}].#{inner_error.attribute}".to_sym + else + "#{association_name}.#{inner_error.attribute}".to_sym + end end def index_errors_setting