active_admin_importable 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
data/app/models/csv_db.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
require 'csv'
|
2
2
|
class CsvDb
|
3
3
|
class << self
|
4
|
-
def convert_save(
|
4
|
+
def convert_save(target_model, csv_data, &block)
|
5
5
|
csv_file = csv_data.read
|
6
|
-
target_model = model_name.pluralize.classify.constantize
|
7
6
|
CSV.parse(csv_file, :headers => true, header_converters: :symbol ) do |row|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
data = row.to_hash
|
8
|
+
if data.present?
|
9
|
+
if (block_given?)
|
10
|
+
block.call(target_model, data)
|
11
|
+
else
|
12
|
+
target_model.create!(data)
|
13
|
+
end
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
@@ -10,7 +10,7 @@ module ActiveAdminImportable
|
|
10
10
|
end
|
11
11
|
|
12
12
|
collection_action :import_csv, :method => :post do
|
13
|
-
CsvDb.convert_save(active_admin_config.
|
13
|
+
CsvDb.convert_save(active_admin_config.resource_class, params[:dump][:file], &block)
|
14
14
|
redirect_to :action => :index, :notice => "#{active_admin_config.resource_name.to_s} imported successfully!"
|
15
15
|
end
|
16
16
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_admin_importable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-30 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: CSV import for Active Admin
|
15
15
|
email:
|