Undefined when accessing through an association and uninitialized constant when trying to destroy with: depend =>: destroy

I tried persistently to search for this error, but to no avail. I currently have these models.

application / models / survey.rb

class Survey < ActiveRecord::Base
  belongs_to :user
  has_attached_file :original, :default_url => "/public/:class/:attachment/:basename.:extension"
  has_many :sub_surveys, :dependent => :destroy
end

application / models / sub_survey.rb

class SubSurvey < ActiveRecord::Base
  belongs_to :survey
  has_many :questions, :dependent => :destroy
end

application / models / question.rb

class Question < ActiveRecord::Base
  belongs_to :sub_survey
  validates_presence_of :sub_survey
  acts_as_list :scope => :sub_survey
  #after_destroy :destroy_orphaned_choices

  has_many :answers, :dependent => :destroy
  has_many :choices, :dependent => :destroy
end

application / models / choice.rb

class Choices < ActiveRecord::Base
  belongs_to :question
  validates_presence_of :question
end

app / models / answer.rb

class Answer < ActiveRecord::Base
  belongs_to :question
  belongs_to :user
  belongs_to :game
  validates_uniqueness_of :question_id, :scope => [:user_id, :game_id]
end

Now when I try to destroy the survey, I get an error

uninitialized constant Question::Choice

This tracks through / vendor / rails / active * after polling. destroy

Then, when I try to access the selections from question.Choices, I get an error

undefined method `Choices' for #<Question:0xb7224f2c>

which for some reason has this on top of the trace stack

vendor/rails/activerecord/lib/active_record/attribute_methods.rb:256:in `method_missing'
vendor/plugins/attribute_fu/lib/attribute_fu/associations.rb:28:in `method_missing'
app/views/answers/_answer.html.erb:7:in `_run_erb_47app47views47answers47_answer46html46erb'

I use the fu attribute when importing polls in xml format, but I have no idea why the question is traced. He is supported.

, .

?

+3
2

Choices , . Choice, has_many :choices class_name. .

has_many :choices, :class_name => 'Choices'

Choice, .

Attachment_fu, , , method_missing, . - .

+4

, ,

undefined method `Choices' for #<Question:0xb7224f2c>

:

question.choices # No capitalization

, .

0

Source: https://habr.com/ru/post/1714058/


All Articles