Skip to content

Commit e6d45a8

Browse files
committed
replaced check_headers_csv with conditional;
rejected rows with any nill values
1 parent a6a3fe7 commit e6d45a8

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

app/controllers/concerns/importable.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)