Skip to content

Commit 7b002e8

Browse files
committed
Merge branch '3.0.0' of https://github.com/Fivell/active_admin_import into 3.0.0
2 parents f9fb05c + 574e9cc commit 7b002e8

File tree

1 file changed

+62
-53
lines changed

1 file changed

+62
-53
lines changed

README.md

Lines changed: 62 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -25,53 +25,63 @@ And then execute:
2525

2626

2727

28-
Why yet another import for ActiveAdmin ? Now with activerecord-import ....
28+
#Why yet another import for ActiveAdmin ? Now with activerecord-import ....
2929

30-
"Because plain-vanilla, out-of-the-box ActiveRecord doesn’t provide support for inserting large amounts of data efficiently"
30+
<p>Because plain-vanilla, out-of-the-box ActiveRecord doesn’t provide support for inserting large amounts of data efficiently</p>
3131

32-
cool features of activerecord-import
32+
Features of activerecord-import
3333

34-
activerecord-import can perform validations (fast)
35-
activerecord-import can perform on duplicate key updates (requires mysql)
36-
37-
38-
So active_admin_import features
39-
40-
Encoding handling
41-
Two step importing (see example2)
42-
CSV options
43-
Ability to prepend CSV headers automatically
44-
Bulk import (activerecord-import)
45-
Ability to customize template
46-
Callbacks support
47-
Zip files import
48-
and more ....
49-
50-
Options
51-
52-
# +back+:: resource action to redirect after processing
53-
# +csv_options+:: hash with column separator, row separator, etc
54-
# +validate+:: true|false, means perform validations or not
55-
# +batch_size+:: integer value of max record count inserted by 1 query/transaction
56-
# +before_import+:: proc for before import action, hook called with importer object
57-
# +after_import+:: proc for after import action, hook called with importer object
58-
# +before_batch_import+:: proc for before each batch action, called with importer object
59-
# +after_batch_import+:: proc for after each batch action, called with importer object
60-
# +on_duplicate_key_update+:: an Array or Hash, tells activerecord-import to use MySQL's ON DUPLICATE KEY UPDATE ability.
61-
# +timestamps+:: true|false, tells activerecord-import to not add timestamps (if false) even if record timestamps is disabled in ActiveRecord::Base
62-
# +ignore+:: true|false, tells activerecord-import toto use MySQL's INSERT IGNORE ability
63-
# +params_keys+:: params values available in callbacks
64-
# +template+:: custom template rendering
65-
# +template_object+:: object passing to view
66-
# +locals+:: local variables for template
67-
# +resource_class+:: resource class name
68-
# +resource_label+:: resource label value
69-
# +plural_resource_label+:: pluralized resource label value (default config.plural_resource_label)
70-
# +headers_rewrites+:: hash with key (csv header) - value (db column name) rows mapping
34+
<ol>
35+
<li>activerecord-import can perform validations (fast)</li>
36+
<li>activerecord-import can perform on duplicate key updates (requires mysql)</li>
37+
</ol>
7138

39+
40+
7241

7342

74-
Default options values
43+
# active_admin_import features
44+
<ol>
45+
<li>Encoding handling</li>
46+
<li>Preview before importing (Example 2)</li>
47+
<li> CSV options</li>
48+
<li> Ability to prepend CSV headers automatically</li>
49+
<li>Bulk import (activerecord-import)</li>
50+
<li>Callbacks</li>
51+
<li>Zip files</li>
52+
<li>more...</li>
53+
</ol>
54+
55+
56+
57+
58+
#### Options
59+
60+
<table>
61+
<tr><td>name</td><td>description</td></tr>
62+
<tr><td>:back</td><td>resource action to redirect after processing</td></tr>
63+
<tr><td>:csv_options</td><td>hash with column separator, row separator, etc </td></tr>
64+
<tr><td>:validate</td><td>true|false, means perform validations or not</td></tr>
65+
<tr><td>:batch_size</td><td>integer value of max record count inserted by 1 query/transaction</td></tr>
66+
<tr><td>:before_import</td><td>proc for before import action, hook called with importer object</td></tr>
67+
<tr><td>:after_import</td><td>proc for after import action, hook called with importer object</td></tr>
68+
<tr><td>:before_batch_import</td><td>proc for before each batch action, called with importer object</td></tr>
69+
<tr><td>:after_batch_import</td><td>proc for after each batch action, called with importer object</td></tr>
70+
<tr><td>:on_duplicate_key_update</td><td>an Array or Hash, tells activerecord-import to use MySQL's ON DUPLICATE KEY UPDATE ability.</td></tr>
71+
<tr><td>:timestamps</td><td>true|false, tells activerecord-import to not add timestamps (if false) even if record timestamps is disabled in ActiveRecord::Base</td></tr>
72+
<tr><td>:ignore</td><td>true|false, tells activerecord-import toto use MySQL's INSERT IGNORE ability</td></tr>
73+
<tr><td>:template</td><td>custom template rendering</td></tr>
74+
<tr><td>:template_object</td><td>object passing to view</td></tr>
75+
<tr><td>:locals</td><td>more variables for template</td></tr>
76+
<tr><td>:resource_class</td><td>resource class name</td></tr>
77+
<tr><td>:resource_label</td><td>resource label value</td></tr>
78+
<tr><td>:plural_resource_label</td><td>pluralized resource label value (default config.plural_resource_label)</td></tr>
79+
<tr><td>:headers_rewrites</td><td>hash with key (csv header) - value (db column name) rows mapping</td></tr>
80+
</table>
81+
82+
83+
84+
#### Default options values
7585

7686
```ruby
7787
back: {action: :import},
@@ -83,7 +93,7 @@ Default options values
8393
plural_resource_label: config.plural_resource_label,
8494
```
8595

86-
Example1
96+
#### Example1
8797

8898
```ruby
8999
ActiveAdmin.register Post do
@@ -97,9 +107,9 @@ Example1
97107
```
98108

99109

100-
Example2 Importing to mediate table with insert select operation after import completion
110+
#### Example2 Importing to mediate table with insert select operation after import completion
101111

102-
This config allows to replace data without downtime
112+
<p> This config allows to replace data in 1 sql query with callback </p>
103113

104114
```ruby
105115
ActiveAdmin.register Post do
@@ -110,15 +120,15 @@ This config allows to replace data without downtime
110120
after_import: proc{
111121
Post.transaction do
112122
Post.delete_all
113-
Post.connection.execute("INSERT INTO posts (SELECT * FROM import_posts)")
123+
Post.connection.execute("INSERT INTO posts (SELECT * FROM imported_posts)")
114124
end
115125
},
116126
back: proc { config.namespace.resource_for(Post).route_collection_path } # redirect to post index
117127
end
118128
```
119129

120130

121-
Example3 Importing file without headers, but we always know file format, so we can predefine it
131+
#### Example3 Importing file without headers, but we always know file format, so we can predefine it
122132

123133
```ruby
124134
ActiveAdmin.register Post do
@@ -130,7 +140,7 @@ Example3 Importing file without headers, but we always know file format, so we c
130140
end
131141
```
132142

133-
Example4 Importing without forcing to UTF-8 and disallow archives
143+
#### Example4 Importing without forcing to UTF-8 and disallow archives
134144

135145

136146
```ruby
@@ -145,7 +155,7 @@ Example4 Importing without forcing to UTF-8 and disallow archives
145155
```
146156

147157

148-
Example5 Callbacks for each bulk insert iteration
158+
#### Example5 Callbacks for each bulk insert iteration
149159

150160

151161
```ruby
@@ -166,9 +176,9 @@ Example5 Callbacks for each bulk insert iteration
166176
end
167177
```
168178

169-
Example6 dynamic CSV options, template overriding
179+
#### Example6 dynamic CSV options, template overriding
170180

171-
1) put overrided template to app/views/import.html.erb
181+
- put overrided template to ```app/views/import.html.erb```
172182

173183
```erb
174184
@@ -194,7 +204,7 @@ Example6 dynamic CSV options, template overriding
194204
195205
```
196206

197-
2) call method with following parameters
207+
- call method with following parameters
198208

199209
```ruby
200210
ActiveAdmin.register Post do
@@ -212,8 +222,7 @@ https://github.com/gregbell/active_admin
212222

213223
https://github.com/zdennis/activerecord-import
214224

215-
#Source Doc
216-
http://rubydoc.info/gems/active_admin_import/2.1.1/
225+
217226

218227

219228

0 commit comments

Comments
 (0)