app/controllers/projects_controller.rb
def copy
    # this duplicates everything but the feature_matrix table
    original_project = Project.find(params[:id])
    new_project      = original_project.amoeba_dup

    # give owner to copying user
    new_project.user = current_user

    # apply changes to database
    new_project.save

    # re-associate feature_matrix table
    original_project.features.each do |original_feature|
      # finding the new id of our feature
      new_feature = new_project.features.find_by orig_feature_id: original_feature.id

      # add one entry for every associated product
      original_feature.products.each do |original_product|
        new_product = new_project.products.find_by orig_product_id: original_product.id
        new_feature.products << new_product
      end
    end

    respond_to do |format|
      format.html { redirect_to editor_index_url(project: new_project.id), notice: "Project successfully copied." }
      format.json { head :no_content }
    end
  end
# creates a copy of the project
creates a copy of the project
creates a copy of the project
def copy
    original_project = Project.find(params[:id])
    new_project      = original_project.amoeba_dup
    new_project.user = current_user
    new_project.save
    original_project.features.each do |original_feature|
      new_feature = new_project.features.find_by orig_feature_id: original_feature.id
      original_feature.products.each do |original_product|
        new_product = new_project.products.find_by orig_product_id: original_product.id
        new_feature.products << new_product
      end
    end
    respond_to do |format|
      format.html { redirect_to editor_index_url(project: new_project.id), notice: "Project successfully copied." }
      format.json { head :no_content }
    end
  end
def copy original_project = Project . find ( params [ :id ] ) new_project = original_project . amoeba_dup new_project . user = current_user new_project . save original_project . features . each do | original_feature | new_feature = new_project . features . find_by orig_feature_id : original_feature . id original_feature . products . each do | original_product | new_product = new_project . products . find_by orig_product_id : original_product . id new_feature . products << new_product end end respond_to do | format | format . html { redirect_to editor_index_url ( project : new_project . id ) , notice : "Project successfully copied." } format . json { head :no_content } end end
creates a copy of the project
creates a copy of the project
# this duplicates everything but the feature_matrix table # give owner to copying user # apply changes to database # re-associate feature_matrix table # finding the new id of our feature # add one entry for every associated product