@@ -16,7 +16,7 @@ with support of validations and bulk inserts
1616Add this line to your application's Gemfile:
1717
1818``` ruby
19- gem " active_admin_import" , ' 2.1.1 '
19+ gem " active_admin_import" , ' ~> 3.0.0 '
2020```
2121
2222And then execute:
@@ -51,7 +51,7 @@ Options
5151
5252 # +back+:: resource action to redirect after processing
5353 # +csv_options+:: hash with column separator, row separator, etc
54- # +validate+:: true|false, means perfoem validations or not
54+ # +validate+:: true|false, means perform validations or not
5555 # +batch_size+:: integer value of max record count inserted by 1 query/transaction
5656 # +before_import+:: proc for before import action, hook called with importer object
5757 # +after_import+:: proc for after import action, hook called with importer object
@@ -66,6 +66,7 @@ Options
6666 # +locals+:: local variables for template
6767 # +resource_class+:: resource class name
6868 # +resource_label+:: resource label value
69+ # +plural_resource_label+:: pluralized resource label value (default config.plural_resource_label)
6970 # +headers_rewrites+:: hash with key (csv header) - value (db column name) rows mapping
7071
7172
@@ -86,10 +87,10 @@ Example1
8687
8788``` ruby
8889 ActiveAdmin .register Post do
89- active_admin_import :validate => false ,
90- : csv_options => { : col_sep => " ;" },
91- : before_import => proc { Post .delete_all},
92- : batch_size => 1000
90+ active_admin_import validate: false ,
91+ csv_options: { col_sep: " ;" },
92+ before_import: proc { Post .delete_all},
93+ batch_size: 1000
9394
9495
9596 end
@@ -102,17 +103,17 @@ This config allows to replace data without downtime
102103
103104``` ruby
104105 ActiveAdmin .register Post do
105- active_admin_import : validate => false ,
106- : csv_options => { : col_sep => " ;" },
107- : resource_class => ImportedPost , # we import data into another resource
108- : before_import => proc { ImportedPost .delete_all },
109- : after_import => proc {
106+ active_admin_import validate: false ,
107+ csv_options: { col_sep: " ;" },
108+ resource_class: ImportedPost , # we import data into another resource
109+ before_import: proc { ImportedPost .delete_all },
110+ after_import: proc {
110111 Post .transaction do
111112 Post .delete_all
112113 Post .connection.execute(" INSERT INTO posts (SELECT * FROM import_posts)" )
113114 end
114115 },
115- : back => proc { config.namespace.resource_for(Post ).route_collection_path } # redirect to post index
116+ back: proc { config.namespace.resource_for(Post ).route_collection_path } # redirect to post index
116117 end
117118```
118119
@@ -121,10 +122,10 @@ Example3 Importing file without headers, but we always know file format, so we c
121122
122123``` ruby
123124 ActiveAdmin .register Post do
124- active_admin_import : validate => true ,
125- : template_object => ActiveAdminImport ::Model .new (
126- : hint => " file will be imported with such header format: 'body','title','author'" ,
127- : csv_headers => [" body" ," title" ," author" ]
125+ active_admin_import validate: true ,
126+ template_object: ActiveAdminImport ::Model .new (
127+ hint: " file will be imported with such header format: 'body','title','author'" ,
128+ csv_headers: [" body" ," title" ," author" ]
128129 )
129130 end
130131```
@@ -134,11 +135,11 @@ Example4 Importing without forcing to UTF-8 and disallow archives
134135
135136``` ruby
136137 ActiveAdmin .register Post do
137- active_admin_import : validate => true ,
138- : template_object => ActiveAdminImport ::Model .new (
139- : hint => " file will be encoded to ISO-8859-1" ,
140- : force_encoding => " ISO-8859-1" ,
141- : allow_archive => false
138+ active_admin_import validate: true ,
139+ template_object: ActiveAdminImport ::Model .new (
140+ hint: " file will be encoded to ISO-8859-1" ,
141+ force_encoding: " ISO-8859-1" ,
142+ allow_archive: false
142143 )
143144 end
144145```
@@ -149,8 +150,8 @@ Example5 Callbacks for each bulk insert iteration
149150
150151``` ruby
151152 ActiveAdmin .register Post do
152- active_admin_import : validate => true ,
153- : before_batch_import => proc { |import |
153+ active_admin_import validate: true ,
154+ before_batch_import: proc { |import |
154155 import.file # current file used
155156 import.resource # ActiveRecord class to import to
156157 import.options # options
@@ -159,7 +160,7 @@ Example5 Callbacks for each bulk insert iteration
159160 import.csv_lines # lines to import
160161 import.model # template_object instance
161162 },
162- : after_batch_import => proc { |import |
163+ after_batch_import: proc { |import |
163164 # the same
164165 }
165166 end
@@ -178,8 +179,8 @@ Example6 dynamic CSV options, template overriding
178179 <%= f.inputs do %>
179180 <%= f.input :file, as: :file %>
180181 <% end %>
181- <%= f.inputs "CSV options", : for => [:csv_options, OpenStruct.new(@active_admin_import_model.csv_options)] do |csv| %>
182- <% csv.with_options : input_html => {: style => 'width:40px;'} do |opts| %>
182+ <%= f.inputs "CSV options", for: [:csv_options, OpenStruct.new(@active_admin_import_model.csv_options)] do |csv| %>
183+ <% csv.with_options input_html: { style: 'width:40px;'} do |opts| %>
183184 <%= opts.input :col_sep %>
184185 <%= opts.input :row_sep %>
185186 <%= opts.input :quote_char %>
@@ -197,11 +198,11 @@ Example6 dynamic CSV options, template overriding
197198
198199``` ruby
199200 ActiveAdmin .register Post do
200- active_admin_import : validate => false ,
201- : template => ' import' ,
202- : template_object => ActiveAdminImport ::Model .new (
203- : hint => " specify CSV options"
204- : csv_options => { : col_sep => " ;" , : row_sep => nil , :quote_char => nil }
201+ active_admin_import validate: false ,
202+ template: ' import' ,
203+ template_object: ActiveAdminImport ::Model .new (
204+ hint: " specify CSV options"
205+ csv_options: { col_sep: " ;" , row_sep: nil , :quote_char : nil }
205206 )
206207 end
207208```
0 commit comments