0

我需要在我的 Rails 应用程序中克隆一个模型,我正在使用amoebagem 来做同样的事情。

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

我需要克隆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

每当我执行上述代码时,都会出现以下错误:

uninitialized constant Quiz::EvaluationsEvaluationSet

我不知道这里的错误在哪里。请告诉我如何纠正它。

4

1 回答 1

0

你需要添加

```
 amoeba do
   enable
 end
```

在调查模型中。

仔细阅读https://github.com/amoeba-rb/amoeba文档。如果您有具有相应关联的克隆对象,那么您应该添加

 amoeba do
    exclude_association
    include_association
    nullify 
  end

克隆对象时使用此类预处理指令。

首先尝试使用 rails 控制台使用 amoeba 克隆对象。

于 2019-06-11T08:40:19.760 回答