add windows content type to avoid errors
This commit is contained in:
parent
ebf0b5ce8f
commit
c731f8cf1f
1 changed files with 5 additions and 2 deletions
|
@ -3,6 +3,10 @@ module NewAdministrateur
|
|||
include ActiveSupport::NumberHelper
|
||||
ITEMS_PER_PAGE = 25
|
||||
CSV_MAX_SIZE = 1.megabytes
|
||||
CSV_ACCEPTED_CONTENT_TYPES = [
|
||||
"text/csv",
|
||||
"application/vnd.ms-excel"
|
||||
]
|
||||
|
||||
def index
|
||||
@procedure = procedure
|
||||
|
@ -161,7 +165,7 @@ module NewAdministrateur
|
|||
end
|
||||
|
||||
def import
|
||||
if (group_csv_file.content_type != "text/csv") && (marcel_content_type != "text/csv")
|
||||
if !CSV_ACCEPTED_CONTENT_TYPES.include?(group_csv_file.content_type) && !CSV_ACCEPTED_CONTENT_TYPES.include?(marcel_content_type)
|
||||
flash[:alert] = "Importation impossible : veuillez importer un fichier CSV"
|
||||
redirect_to admin_procedure_groupe_instructeurs_path(procedure)
|
||||
|
||||
|
@ -171,7 +175,6 @@ module NewAdministrateur
|
|||
|
||||
else
|
||||
file = group_csv_file.read
|
||||
# find the original encoding to avoid encoding errors
|
||||
base_encoding = CharlockHolmes::EncodingDetector.detect(file)
|
||||
groupes_emails = CSV.new(file.encode("UTF-8", base_encoding[:encoding], invalid: :replace, replace: ""), headers: true, header_converters: :downcase)
|
||||
.map { |r| r.to_h.slice('groupe', 'email') }
|
||||
|
|
Loading…
Add table
Reference in a new issue