Handle CSV::MalformedCSVError
This commit is contained in:
@@ -46,33 +46,39 @@ class ItemsController < ApplicationController
|
|||||||
@csv_content = params[:csv_content]
|
@csv_content = params[:csv_content]
|
||||||
|
|
||||||
@error_message = ""
|
@error_message = ""
|
||||||
|
@output = []
|
||||||
|
|
||||||
if params[:csv_content] == ""
|
if params[:csv_content] == ""
|
||||||
@error_message = "Format of CSV is wrong (CSV content is empty)"
|
@error_message = "Format of CSV is wrong (CSV content is empty)"
|
||||||
else
|
else
|
||||||
csv_parsed = CSV.parse(params[:csv_content])
|
|
||||||
csv_file = ItemsHelper::create_csv(csv_parsed)
|
|
||||||
|
|
||||||
@output = ""
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
ENV["INPUT"] = csv_file.path
|
csv_parsed = CSV.parse(params[:csv_content])
|
||||||
|
rescue CSV::MalformedCSVError => er
|
||||||
|
@error_message = "Format of CSV is wrong (#{er.message})"
|
||||||
|
end
|
||||||
|
|
||||||
case params[:task]
|
unless csv_parsed.nil?
|
||||||
when 'validate_items'
|
csv_file = ItemsHelper::create_csv(csv_parsed)
|
||||||
@output = ItemsHelper::execute_command("rake ribica:validate_items")
|
|
||||||
#ItemsHelper::execute_command("rake ribica:reindex")
|
begin
|
||||||
when 'import_items'
|
ENV["INPUT"] = csv_file.path
|
||||||
@output = ItemsHelper::execute_command("rake ribica:import_items")
|
|
||||||
#ItemsHelper::execute_command("rake ribica:reindex")
|
case params[:task]
|
||||||
when 'update_prices'
|
when 'validate_items'
|
||||||
@output = ItemsHelper::execute_command("rake ribica:update_prices")
|
@output = ItemsHelper::execute_command("rake ribica:validate_items")
|
||||||
#ItemsHelper::execute_command("rake ribica:reindex")
|
#ItemsHelper::execute_command("rake ribica:reindex")
|
||||||
else
|
when 'import_items'
|
||||||
@error_message = "There is no such task"
|
@output = ItemsHelper::execute_command("rake ribica:import_items")
|
||||||
|
#ItemsHelper::execute_command("rake ribica:reindex")
|
||||||
|
when 'update_prices'
|
||||||
|
@output = ItemsHelper::execute_command("rake ribica:update_prices")
|
||||||
|
#ItemsHelper::execute_command("rake ribica:reindex")
|
||||||
|
else
|
||||||
|
@error_message = "There is no such task"
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
csv_file.unlink
|
||||||
end
|
end
|
||||||
ensure
|
|
||||||
csv_file.unlink
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@output = @output.join("<br/>")
|
@output = @output.join("<br/>")
|
||||||
|
|||||||
Reference in New Issue
Block a user