我一直尝试在谷歌上搜索这个错误,但无济于事。我目前有这些模型
应用程序/模型/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
应用程序/模型/sub_survey.rb
class SubSurvey < ActiveRecord::Base
belongs_to :survey
has_many :questions, :dependent => :destroy
end
应用程序/模型/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
应用程序/模型/choice.rb
class Choices < ActiveRecord::Base
belongs_to :question
validates_presence_of :question
end
应用程序/模型/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
现在,当我尝试销毁调查时,出现错误
uninitialized constant Question::Choice
在survey.destroy之后通过/vendor/rails/active*的东西追踪
然后,当我尝试从 question.Choices 访问选项时,出现错误
undefined method `Choices' for #<Question:0xb7224f2c>
由于某种原因,它在跟踪堆栈的顶部
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'
在以 xml 格式导入调查时,我确实使用了 attribute_fu,但我不知道为什么 question.Choices 的痕迹有它。
我还尝试将选项重命名为选择选项,但这没有效果。
有任何想法吗?