、 のアプリがあり、og_objects
この
アプリのクローンを作成する方法を作成しました。og_actions
stories
og_objects
、og_actions
およびをクローンに複製しようとしてstories
いますが、行き詰っています。
2か所引っかかってます。
1. クローンを作成すると、オブジェクト、アクション、ストーリーが新しいクローンに移動されますが、それらは複製されません。つまり、親アプリはそれらを失います。
2. 新しいクローンに og_objects プロパティがないというエラーが表示されます。具体的には、エラーは次のとおりです。
ActiveModel::MissingAttributeError (can't write unknown attribute `og_actions'):
app/models/app.rb:39:in `block in populate'
app/models/app.rb:36:in `populate'
app/models/app_generator.rb:15:in `generate'
app/controllers/apps_controller.rb:12:in `create'
これは私が持っているコードです:
class App < ActiveRecord::Base
validates :name, :presence => true, :uniqueness => {:scope => :dev_mode}
validates :user_id, :presence => true
before_validation :validate_app
belongs_to :user
has_many :og_actions
has_many :og_objects
has_many :stories
has_many :log_reports
has_many :clones, class_name: "App", foreign_key: "parent_id"
belongs_to :parent_app, class_name: "App"
def self.dev_modes
['development', 'stage', 'production']
end
def is_clone?
!!self.parent_id
end
def clone_ids
if !is_clone?
self.clones.all.map(&id)
end
end
def populate
p "doing populate"
p self.clones
p "original clones"
new_og_actions = self.og_actions.dup
new_og_objects = self.og_objects.dup
new_stories = self.stories.dup
self.clones.each do |c|
p "updating ->"
p c
c[:og_actions] = new_og_actions
c[:og_objects] = new_og_objects
c[:stories] = new_stories
end
end
#Other irrelevant code here:
私のコントローラーにはジェネレーターがあり、次のコードがあります。
if @parent_id.length > 0
parent_app = App.find(@parent_id)
App.create_with(og_actions: parent_app.og_actions.dup, og_objects: parent_app.og_objects.dup, stories:parent_app.stories.dup, parent_id: @parent_id, user_id: @user_id, app_id:@app_id, app_secret: @app_secret).find_or_create_by!(name: @name, dev_mode: 'clone')
parent_app.populate
else