active_scaffold_duplicate 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.textile +16 -4
- data/lib/active_scaffold/actions/duplicate.rb +10 -2
- data/lib/active_scaffold_duplicate/version.rb +1 -1
- metadata +27 -65
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA512:
|
3
|
+
data.tar.gz: fe4482042e71ce1e6bcc63b89b863c254f92d421b32599109f919858fd465382e45d2f8efd2377966499420fb3b7689e5a0d53d4ce8ae0650a4b0cfe38af3355
|
4
|
+
metadata.gz: bb3a717673f55a665db6c817f41439a191d3fadf9a0b58d2f0e77eff71e4cbfb50273580bc8deb7a0c0848faee526ad43a5ec4f89d90e1ad12ebc9da575a37c1
|
5
|
+
SHA1:
|
6
|
+
data.tar.gz: 86c1f70bcb1c2d68272246587de58b7219ade71b
|
7
|
+
metadata.gz: dab546f0a8408f5a9999e9d91d419d548884427b
|
data/README.textile
CHANGED
@@ -19,7 +19,7 @@ h2. Usage
|
|
19
19
|
|
20
20
|
h4. Step 1
|
21
21
|
|
22
|
-
Override
|
22
|
+
Override initialize_dup in the model to set some attributes or copy associations:
|
23
23
|
|
24
24
|
<pre>
|
25
25
|
# app/models/bill.rb
|
@@ -48,12 +48,14 @@ end
|
|
48
48
|
|
49
49
|
h4. Step 3
|
50
50
|
|
51
|
-
Change method to :get in link if you want to display create form instead of cloning record.
|
51
|
+
Change method to :get in link if you want to display create form instead of cloning record. Set position to :replace or :after for inline display, or enable page rendering.
|
52
52
|
|
53
53
|
<pre>
|
54
54
|
class BillsController < ApplicationController
|
55
55
|
active_scaffold do |conf|
|
56
|
-
conf.duplicate.link.
|
56
|
+
conf.duplicate.link.method = :get
|
57
|
+
conf.duplicate.link.position = :after
|
58
|
+
#conf.duplicate.link.page = true # for new page rendering
|
57
59
|
end
|
58
60
|
end
|
59
61
|
</pre>
|
@@ -63,11 +65,14 @@ Also you can change it globally.
|
|
63
65
|
<pre>
|
64
66
|
class ApplicationController < ActionController::Base
|
65
67
|
active_scaffold.set_defaults do |conf|
|
66
|
-
conf.duplicate.link.
|
68
|
+
conf.duplicate.link.method = :get
|
69
|
+
conf.duplicate.link.position = :after
|
70
|
+
#conf.duplicate.link.page = true # for new page rendering
|
67
71
|
end
|
68
72
|
end
|
69
73
|
</pre>
|
70
74
|
|
75
|
+
You can access to record which is being duplicated in your form overrides with @old_record variable.
|
71
76
|
|
72
77
|
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:
|
73
78
|
|
@@ -76,6 +81,13 @@ If you use :post method, you can enable refresh_list to refresh the list instead
|
|
76
81
|
conf.duplicate.action_after_clone = :edit
|
77
82
|
</pre>
|
78
83
|
|
84
|
+
h2. Before/after controller methods
|
85
|
+
|
86
|
+
It's possible to define some methods to add some custom code which require access to session or request params:
|
87
|
+
|
88
|
+
* For :post method, before_duplicate_save(record) and after_duplicate_save(record) can be defined, which will be called before and after saving the record respectively.
|
89
|
+
* For :new method, before_duplicate_new(record) can be defined, which will be called before rendering.
|
90
|
+
|
79
91
|
h2. Support
|
80
92
|
|
81
93
|
If you have issues installing the gem, search / post to the "Active Scaffold":http://groups.google.com/group/activescaffold forum or "Create an issue":http://github.com/activescaffold/active_scaffold_clone/issues
|
@@ -5,17 +5,25 @@ module ActiveScaffold::Actions
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def duplicate
|
8
|
-
old_record = find_if_allowed(params[:id], :read)
|
9
|
-
@record = old_record.send(active_scaffold_config.duplicate.method)
|
8
|
+
@old_record = find_if_allowed(params[:id], :read)
|
9
|
+
@record = @old_record.send(active_scaffold_config.duplicate.method)
|
10
10
|
if request.post?
|
11
|
+
before_duplicate_save(@record)
|
11
12
|
self.successful = @record.save
|
13
|
+
after_duplicate_save(@record) if successful?
|
12
14
|
respond_to_action(:duplicate)
|
13
15
|
else
|
16
|
+
params.delete :id
|
17
|
+
before_duplicate_new(@record)
|
14
18
|
respond_to_action(:new)
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
18
22
|
protected
|
23
|
+
def before_duplicate_save(record); end
|
24
|
+
def before_duplicate_new(record); end
|
25
|
+
def after_duplicate_save(record); end
|
26
|
+
|
19
27
|
def duplicate_authorized?(record = nil)
|
20
28
|
(record || self).authorized_for?(:crud_type => :create, :action => :duplicate)
|
21
29
|
end
|
metadata
CHANGED
@@ -1,13 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_scaffold_duplicate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 0
|
10
|
-
version: 1.0.0
|
4
|
+
version: 1.0.1
|
11
5
|
platform: ruby
|
12
6
|
authors:
|
13
7
|
- Sergio Cambra
|
@@ -15,69 +9,47 @@ autorequire:
|
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
11
|
|
18
|
-
date:
|
12
|
+
date: 2014-02-17 00:00:00 Z
|
19
13
|
dependencies:
|
20
14
|
- !ruby/object:Gem::Dependency
|
21
|
-
|
22
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
-
none: false
|
15
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
16
|
requirements:
|
25
|
-
-
|
17
|
+
- &id003
|
18
|
+
- ">="
|
26
19
|
- !ruby/object:Gem::Version
|
27
|
-
hash: 3
|
28
|
-
segments:
|
29
|
-
- 0
|
30
20
|
version: "0"
|
31
|
-
|
32
|
-
prerelease: false
|
21
|
+
type: :development
|
33
22
|
name: shoulda
|
23
|
+
requirement: *id001
|
24
|
+
prerelease: false
|
34
25
|
- !ruby/object:Gem::Dependency
|
35
|
-
|
36
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
-
none: false
|
26
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
38
27
|
requirements:
|
39
28
|
- - ~>
|
40
29
|
- !ruby/object:Gem::Version
|
41
|
-
hash: 23
|
42
|
-
segments:
|
43
|
-
- 1
|
44
|
-
- 0
|
45
|
-
- 0
|
46
30
|
version: 1.0.0
|
47
|
-
|
48
|
-
prerelease: false
|
31
|
+
type: :development
|
49
32
|
name: bundler
|
33
|
+
requirement: *id002
|
34
|
+
prerelease: false
|
50
35
|
- !ruby/object:Gem::Dependency
|
51
|
-
|
52
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
-
none: false
|
36
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
54
37
|
requirements:
|
55
|
-
-
|
56
|
-
|
57
|
-
hash: 3
|
58
|
-
segments:
|
59
|
-
- 0
|
60
|
-
version: "0"
|
61
|
-
version_requirements: *id003
|
62
|
-
prerelease: false
|
38
|
+
- *id003
|
39
|
+
type: :development
|
63
40
|
name: rcov
|
41
|
+
requirement: *id004
|
42
|
+
prerelease: false
|
64
43
|
- !ruby/object:Gem::Dependency
|
65
|
-
|
66
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
-
none: false
|
44
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
68
45
|
requirements:
|
69
46
|
- - ">="
|
70
47
|
- !ruby/object:Gem::Version
|
71
|
-
hash: -615719623
|
72
|
-
segments:
|
73
|
-
- 3
|
74
|
-
- 3
|
75
|
-
- 0
|
76
|
-
- rc
|
77
48
|
version: 3.3.0.rc
|
78
|
-
|
79
|
-
prerelease: false
|
49
|
+
type: :runtime
|
80
50
|
name: active_scaffold
|
51
|
+
requirement: *id005
|
52
|
+
prerelease: false
|
81
53
|
description: Clone records using a method from model in ActiveScaffold
|
82
54
|
email: activescaffold@googlegroups.com
|
83
55
|
executables: []
|
@@ -124,35 +96,25 @@ files:
|
|
124
96
|
homepage: http://github.com/activescaffold/active_scaffold_duplicate
|
125
97
|
licenses:
|
126
98
|
- MIT
|
99
|
+
metadata: {}
|
100
|
+
|
127
101
|
post_install_message:
|
128
102
|
rdoc_options: []
|
129
103
|
|
130
104
|
require_paths:
|
131
105
|
- lib
|
132
106
|
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
-
none: false
|
134
107
|
requirements:
|
135
|
-
-
|
136
|
-
- !ruby/object:Gem::Version
|
137
|
-
hash: 3
|
138
|
-
segments:
|
139
|
-
- 0
|
140
|
-
version: "0"
|
108
|
+
- *id003
|
141
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
-
none: false
|
143
110
|
requirements:
|
144
|
-
-
|
145
|
-
- !ruby/object:Gem::Version
|
146
|
-
hash: 3
|
147
|
-
segments:
|
148
|
-
- 0
|
149
|
-
version: "0"
|
111
|
+
- *id003
|
150
112
|
requirements: []
|
151
113
|
|
152
114
|
rubyforge_project:
|
153
|
-
rubygems_version:
|
115
|
+
rubygems_version: 2.0.7
|
154
116
|
signing_key:
|
155
|
-
specification_version:
|
117
|
+
specification_version: 4
|
156
118
|
summary: Clone record gem for Activescaffold
|
157
119
|
test_files:
|
158
120
|
- test/auto_models_controller_test.rb
|