class ActiveRecord::Associations::NestedError

Attributes

association[R]

Public Class Methods

new(association, inner_error) click to toggle source
Calls superclass method
# File lib/active_record/associations/nested_error.rb, line 8
def initialize(association, inner_error)
  @base = association.owner
  @association = association
  @inner_error = inner_error
  super(@base, inner_error, { attribute: compute_attribute(inner_error) })
end

Private Instance Methods

compute_attribute(inner_error) click to toggle source
# File lib/active_record/associations/nested_error.rb, line 18
def compute_attribute(inner_error)
  association_name = association.reflection.name

  if association.collection? && index_errors_setting && index
    "#{association_name}[#{index}].#{inner_error.attribute}".to_sym
  else
    "#{association_name}.#{inner_error.attribute}".to_sym
  end
end
index() click to toggle source
# File lib/active_record/associations/nested_error.rb, line 33
def index
  @index ||= ordered_records&.find_index(inner_error.base)
end
index_errors_setting() click to toggle source
# File lib/active_record/associations/nested_error.rb, line 28
def index_errors_setting
  @index_errors_setting ||=
    association.options.fetch(:index_errors, ActiveRecord.index_nested_attribute_errors)
end
ordered_records() click to toggle source
# File lib/active_record/associations/nested_error.rb, line 37
def ordered_records
  case index_errors_setting
  when true # default is association order
    association.target
  when :nested_attributes_order
    association.nested_attributes_target
  end
end