<commit_before>h1. Drag-Drop Sortable for ActiveScaffold

Currently, this gem is compatible with rails 3.x and ActiveScaffold 3.3.x gems.

h2. Overview

This gem adds an action to clone records. 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.

h2. Installation

You'll need at least ActiveScaffold 3.3.x to use this, and rails 3.x


<pre>
gem install active_scaffold_duplicate
</pre>

h2. Usage

h4. Step 1

Override intialize_dup in the model:

<pre>
# app/models/bill.rb
class Bill < ActiveRecord::Base
  belongs_to :customer
  has_many :items
  
  def initialize_dup(other)
    super
    self.items = other.items.map(&:dup)
  end
end
</pre>

h4. Step 2

Add duplicate action.

<pre>
class BillsController < ApplicationController
  active_scaffold do |conf|
    conf.actions << :duplicate
  end
end
</pre>

h4. Step 3

Change method to :get in link if you want to display create form instead of cloning record.

<pre>
class BillsController < ApplicationController
  active_scaffold do |conf|
    conf.duplicate.link.options.method = :get
  end
end
</pre>

Also you can change it globally.

<pre>
class ApplicationController < ActionController::Base
  active_scaffold.set_defaults do |conf|
    conf.duplicate.link.options.method = :get
  end
end
</pre>


If you use :post method, you can enable refresh_list to refresh the list instead of only adding new record at top, or set action_after_clone to open edit form for example:

<pre>
  conf.duplicate.refresh_list = true<commit_msg>fix doc about changing method to display form<commit_after>h1. Drag-Drop Sortable for ActiveScaffold

Currently, this gem is compatible with rails 3.x and ActiveScaffold 3.3.x gems.

h2. Overview

This gem adds an action to clone records. 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.

h2. Installation

You'll need at least ActiveScaffold 3.3.x to use this, and rails 3.x


<pre>
gem install active_scaffold_duplicate
</pre>

h2. Usage

h4. Step 1

Override intialize_dup in the model:

<pre>
# app/models/bill.rb
class Bill < ActiveRecord::Base
  belongs_to :customer
  has_many :items
  
  def initialize_dup(other)
    super
    self.items = other.items.map(&:dup)
  end
end
</pre>

h4. Step 2

Add duplicate action.

<pre>
class BillsController < ApplicationController
  active_scaffold do |conf|
    conf.actions << :duplicate
  end
end
</pre>

h4. Step 3

Change method to :get in link if you want to display create form instead of cloning record. Set position to :replace or :after.

<pre>
class BillsController < ApplicationController
  active_scaffold do |conf|
    conf.duplicate.link.method = :get
    conf.duplicate.link.position = :after
  end
end
</pre>

Also you can change it globally.

<pre>
class ApplicationController < ActionController::Base
  active_scaffold.set_defaults do |conf|
    conf.duplicate.link.method = :get
    conf.duplicate.link.position = :after
  end
end
</pre>


If you use :post method, you can enable refresh_list to refresh the list instead of only adding new record at top, or set action_after_clone to open edit form for example:

<pre>
  conf.duplicate.refresh_list = true
{'fraction_non_alphanumeric': 0.06956779159265838, 'fraction_numerical': 0.009473060982830076, 'mean_word_length': 3.9618208516886932, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4113225', 'n_tokens_mistral': 1087, 'n_tokens_neox': 1044, 'n_words': 420}