[英]Rails + Amoeba error: Uninitialized constant
I need to clone a model in my Rails application and I am using amoeba
gem to do the same. 我需要在我的Rails应用程序中克隆模型,并且我使用
amoeba
gem来做同样的事情。
class Quiz
belongs_to :scoring
belongs_to :skill
has_many :questions, :dependent => :destroy
has_many :attempts, :dependent => :destroy
has_many :quizzes_test_profiles, :dependent => :destroy
has_many :test_profiles, :through => :quizzes_test_profiles
has_many :evaluations_evaluation_sets, as: :resource
amoeba do
enable
end
end
class EvaluationsEvaluationSet
belongs_to :test_profile
belongs_to :resource, polymorphic: true
belongs_to :evaluation_set
end
I need to clone Quiz
model with all its nested associations. 我需要克隆
Quiz
模型及其所有嵌套关联。
class QuizzesController
def duplicate_survey
id = params[:id]
original_survey = Survey.find(id)
respond_to do |format|
new_survey = original_survey.amoeba_dup
new_survey.save
if new_survey
flash[:notice] = 'Survey successfully cloned.'
else
flash[:error] = 'Survey could not be cloned'
end
format.html {redirect_to :back}
end
end
end
Whenever I execute the above code, I get the following error: 每当我执行上面的代码时,我都会收到以下错误:
uninitialized constant Quiz::EvaluationsEvaluationSet
I do not know where is the mistake here. 我不知道这里的错误在哪里。 Please tell me how to rectify it.
请告诉我如何纠正它。
you need to add 你需要添加
```
amoeba do
enable
end
```
in Survey model . 在调查模型中。
Read https://github.com/amoeba-rb/amoeba docs carefully . 请仔细阅读https://github.com/amoeba-rb/amoeba文档。 if you have clone object with there respective association then you should have to add
如果你有克隆对象有相应的关联,那么你应该添加
amoeba do
exclude_association
include_association
nullify
end
use such preprocessing directives when cloning the object. 克隆对象时使用此类预处理指令。
first try with rails console for cloning the object by using amoeba . 首先尝试使用rails控制台通过使用变形虫来克隆对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.