Adds an action to clone records, and support to clone rows in subforms.

Requirements

  • Active Scaffold 4.4.0 or newer
  • A Ruby and Rails version supported by the selected Active Scaffold version

Description

By default will only set attributes and belongs_to associations. You must override initialize_dup in your model or define a method to clone the record and set in conf.duplicate.method.

Duplicating rows in a subform requires the :duplicate setting in the column’s options or form_ui_options.

Installation

Add the following line to your Gemfile:

gem 'active_scaffold_duplicate'

Then run:

bundle install

Usage & Options

Enable the duplicate action in your controller:

class OrdersController < ApplicationController
  active_scaffold :order do |config|
    config.actions << :duplicate
  end
end

Example Code

class OrdersController < ApplicationController
  active_scaffold do |conf|
    conf.duplicate.link.method = :get
    conf.duplicate.link.position = :after
    #conf.duplicate.link.page = true # for new page rendering
    conf.columns[:lines].form_ui = nil, {duplicate: true} # add a button to duplicate a line in the subform
  end
end

UI adapter support

ActiveScaffold Duplicate 2.1 exposes the link that duplicates an association-subform row as the subform_record_duplicate UI element. A UI adapter can add classes, accessibility attributes, and other presentation attributes without overriding the plugin helper:

ActiveScaffold.add_element_attributes :subform_record_duplicate,
                                      class: "btn btn-sm btn-secondary"

Adapter attributes are merged with the dup class, remote-link setting, visibility style, and data-scope attribute required by the plugin. See Customizing UI Markup and Integrating CSS Frameworks for the complete UI adapter API.

Tutorial

Follow Duplicating rows in subforms to enable the row action, understand what is copied, and customize the duplicated record before it is added to the form.

Get Plugin