diff --git a/app/controllers/channels_controller.rb b/app/controllers/channels_controller.rb index 2f1d71f..7590096 100644 --- a/app/controllers/channels_controller.rb +++ b/app/controllers/channels_controller.rb @@ -425,7 +425,7 @@ class ChannelsController < ApplicationController # if no data if params[:upload].blank? || params[:upload][:csv].blank? - flash[:error] = t(:upload_no_file) + flash[:alert] = t(:upload_no_file) redirect_to channel_path(channel.id, :anchor => "dataimport") and return end @@ -433,10 +433,19 @@ class ChannelsController < ApplicationController Time.zone = params[:feed][:time_zone] Chronic.time_class = Time.zone - # read data from uploaded file - csv_array = CSV.parse(params[:upload][:csv].read) + # make sure uploaded file doesn't cause errors + csv_array = nil + flash_alert = nil + begin + # read data from uploaded file + csv_array = CSV.parse(params[:upload][:csv].read) + rescue CSV::MalformedCSVError + flash_alert = t(:upload_incorrect_format) + end + + # if no data read, output error message if csv_array.nil? || csv_array.blank? - flash[:error] = t(:upload_no_data) + flash[:alert] = flash_alert || t(:upload_no_data) redirect_to channel_path(channel.id, :anchor => "dataimport") and return end diff --git a/config/locales/en.yml b/config/locales/en.yml index 4f779c0..85c811e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -398,6 +398,7 @@ en: twitter_new_api_key: "Regenerate API Key" twitter_screen_name: "Twitter Account" upload: "Upload" + upload_incorrect_format: "Your CSV file is not properly formatted." upload_select: "Upload a CSV file to import data into this channel" uploading: "uploading file..." upload_successful: "Upload successful."