Reputation: 1139
I need to clone a model in my Rails application and I am using amoeba
gem to do the same.
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.
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.
Upvotes: 0
Views: 170
Reputation: 16
you need to add
```
amoeba do
enable
end
```
in Survey model .
Read https://github.com/amoeba-rb/amoeba docs carefully . 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 .
Upvotes: 0