Class: ActiveRecord::Associations::NestedError
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
::ActiveModel::NestedError ,
Forwardable,
::ActiveModel::Error
|
|
Instance Chain:
|
|
Inherits: |
ActiveModel::NestedError
|
Defined in: | activerecord/lib/active_record/associations/nested_error.rb |
Constant Summary
::ActiveModel::Error
- Inherited
Class Attribute Summary
Class Method Summary
- .new(association, inner_error) ⇒ NestedError constructor
::ActiveModel::NestedError
- Inherited
::ActiveModel::Error
- Inherited
Instance Attribute Summary
- #association readonly private
::ActiveModel::NestedError
- Inherited
::ActiveModel::Error
- Inherited
#attribute | The attribute of |
#base | The object which the error belongs to. |
#i18n_customize_full_message, #i18n_customize_full_message?, | |
#options | The options provided when calling |
#raw_type | The raw value provided as the second parameter when calling |
#type | The type of error, defaults to |
Instance Method Summary
- #compute_attribute(inner_error) private
- #index private
- #index_errors_setting private
- #ordered_records private
::ActiveModel::Error
- Inherited
#detail | Alias for ActiveModel::Error#details. |
#details | Returns the error details. |
#eql? | Alias for ActiveModel::Error#==. |
#full_message | Returns the full error message. |
#match? | See if error matches provided |
#message | Returns the error message. |
#strict_match? | See if error matches provided |
#attributes_for_hash, #==, #hash, #initialize_dup, #inspect |
Constructor Details
.new(association, inner_error) ⇒ NestedError
# File 'activerecord/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
Instance Attribute Details
#association (readonly, private)
[ GitHub ]# File 'activerecord/lib/active_record/associations/nested_error.rb', line 16
attr_reader :association
Instance Method Details
#compute_attribute(inner_error) (private)
[ GitHub ]# File 'activerecord/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 (private)
[ GitHub ]# File 'activerecord/lib/active_record/associations/nested_error.rb', line 33
def index @index ||= ordered_records&.find_index(inner_error.base) end
#index_errors_setting (private)
[ GitHub ]# File 'activerecord/lib/active_record/associations/nested_error.rb', line 28
def index_errors_setting @index_errors_setting ||= association. .fetch(:index_errors, ActiveRecord.index_nested_attribute_errors) end
#ordered_records (private)
[ GitHub ]# File 'activerecord/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