Add mass import of commercials

Fix #1055
This commit is contained in:
Stella Rouzi 2017-01-11 16:45:58 +02:00
parent efb12b02e8
commit 32fa0bde6b
6 changed files with 97 additions and 29 deletions

View file

@ -49,6 +49,26 @@ module Admin
end
end
##
# Received a file from user
# Reads file and creates commercial for event
# File content example:
# EventID:MyURL
def mass_upload
errors = Commercial.read_file(params[:file]) if params[:file]
if errors.all? { |_k, v| v.blank? }
flash[:notice] = 'Successfully added commercials.'
else
errors_text = ''
errors_text << 'Unable to find event with ID: ' + errors[:no_event].join(', ') + '. ' if errors[:no_event].any?
errors_text << 'There were some errors: ' + errors[:validation_errors].join('. ') if errors[:validation_errors].any?
flash[:error] = errors_text
end
redirect_to :back
end
private
def commercial_params