Exception: ActiveRecord::AssociationNotFoundError

Inherits:
ConfigurationError show all
Includes:
DidYouMean::Correctable
Defined in:
lib/active_record/associations/errors.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record = nil, association_name = nil) ⇒ AssociationNotFoundError

Returns a new instance of AssociationNotFoundError.



7
8
9
10
11
12
13
14
15
# File 'lib/active_record/associations/errors.rb', line 7

def initialize(record = nil, association_name = nil)
  @record           = record
  @association_name = association_name
  if record && association_name
    super("Association named '#{association_name}' was not found on #{record.class.name}; perhaps you misspelled it?")
  else
    super("Association was not found.")
  end
end

Instance Attribute Details

#association_nameObject (readonly)

Returns the value of attribute association_name.



5
6
7
# File 'lib/active_record/associations/errors.rb', line 5

def association_name
  @association_name
end

#recordObject (readonly)

Returns the value of attribute record.



5
6
7
# File 'lib/active_record/associations/errors.rb', line 5

def record
  @record
end

Instance Method Details

#correctionsObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/active_record/associations/errors.rb', line 20

def corrections
  if record && association_name
    @corrections ||= begin
      maybe_these = record.class.reflections.keys
      DidYouMean::SpellChecker.new(dictionary: maybe_these).correct(association_name)
    end
  else
    []
  end
end