Skip to content

Commit 2cf0756

Browse files
committed
allow change headers in callabcks, specs added
1 parent cb44dc2 commit 2cf0756

File tree

4 files changed

+104
-78
lines changed

4 files changed

+104
-78
lines changed

lib/active_admin_import/importer.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
module ActiveAdminImport
33
class Importer
44

5-
attr_reader :resource, :options, :result, :headers, :csv_lines, :model
5+
attr_reader :resource, :options, :result, :model
6+
attr_accessor :csv_lines, :headers
67

78
OPTIONS = [
89
:validate,
@@ -85,7 +86,7 @@ def process_file
8586
end
8687

8788
def prepare_headers
88-
headers = self.headers.present? ? self.headers : yield
89+
headers = self.headers.present? ? self.headers.map(&:to_s) : yield
8990
@headers = Hash[headers.zip(headers.map { |el| el.underscore.gsub(/\s+/, '_') })].with_indifferent_access
9091
@headers.merge!(options[:headers_rewrites].symbolize_keys.slice(*@headers.symbolize_keys.keys))
9192
@headers
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"Title","Body"
2+
"title1","some body"
3+
"title2","some body"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"title1","some body"
2+
"title2","some body"

0 commit comments

Comments
 (0)