diff --git a/app/models/csv_db.rb b/app/models/csv_db.rb index f15b4d1..3f83ea9 100644 --- a/app/models/csv_db.rb +++ b/app/models/csv_db.rb @@ -1,13 +1,13 @@ require 'csv' class CsvDb class << self - def convert_save(target_model, csv_data, &block) + def convert_save(target_model, csv_data, session, &block) csv_file = csv_data.read CSV.parse(csv_file, :headers => true, header_converters: :symbol ) do |row| data = row.to_hash if data.present? if (block_given?) - block.call(target_model, data) + block.call(target_model, data, session) else target_model.create!(data) end @@ -15,4 +15,4 @@ def convert_save(target_model, csv_data, &block) end end end -end \ No newline at end of file +end diff --git a/lib/active_admin_importable/dsl.rb b/lib/active_admin_importable/dsl.rb index ea79938..020c76d 100644 --- a/lib/active_admin_importable/dsl.rb +++ b/lib/active_admin_importable/dsl.rb @@ -10,9 +10,9 @@ def active_admin_importable(&block) end collection_action :import_csv, :method => :post do - CsvDb.convert_save(active_admin_config.resource_class, params[:dump][:file], &block) + CsvDb.convert_save(active_admin_config.resource_class, params[:dump][:file], session, &block) redirect_to :action => :index, :notice => "#{active_admin_config.resource_name.to_s} imported successfully!" end end end -end \ No newline at end of file +end