File tree Expand file tree Collapse file tree 1 file changed +2
-10
lines changed
Expand file tree Collapse file tree 1 file changed +2
-10
lines changed Original file line number Diff line number Diff line change @@ -26,8 +26,8 @@ module Importable
2626 def import_csv
2727 if params [ :file ] . present?
2828 data = File . read ( params [ :file ] . path , encoding : "BOM|UTF-8" )
29- csv = CSV . parse ( data , headers : true )
30- if check_headers_csv ( csv )
29+ csv = CSV . parse ( data , headers : true ) . reject { | row | row . to_hash . values . any? ( & :nil? ) }
30+ if csv . count . positive? && csv . first . headers . all? { | header | ! header . nil? }
3131 resource_model . import_csv ( csv , current_organization . id )
3232 flash [ :notice ] = "#{ resource_model_humanized } were imported successfully!"
3333 else
@@ -39,14 +39,6 @@ def import_csv
3939 redirect_back ( fallback_location : { action : :index , organization_id : current_organization } )
4040 end
4141
42- def check_headers_csv ( csv )
43- if csv . count . positive? && csv . first . headers . all? { |header | !header . nil? }
44- return true
45- end
46-
47- false
48- end
49-
5042 private
5143
5244 def resource_model
You can’t perform that action at this time.
0 commit comments