File tree Expand file tree Collapse file tree
app/models/concerns/csv2db Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11module Csv2db ::ActiveStorageAdapter
22 extend ActiveSupport ::Concern
3-
43 FILE_TYPE = 'text/csv' . freeze
54
65 included do
76 has_one_attached :csv_upload
7+
8+ validate :check_file_extension
89 end
910
1011 def file = ( file )
1112 # Override Dragonfly setter method
1213 csv_upload . attach (
1314 io : file . tempfile ,
1415 filename : file . original_filename ,
15- content_type : FILE_TYPE
16+ content_type : file . content_type
1617 )
1718 end
1819
1920 private
2021
22+ def check_file_extension
23+ # very basic check of file extension
24+ errors . add ( :file , I18n . t ( 'shared.file_processor.incorrect_file_type' ) ) unless csv_upload . blob . content_type == FILE_TYPE
25+ end
26+
2127 def file_data
2228 return @file_data if @file_data . present?
2329
Original file line number Diff line number Diff line change @@ -194,7 +194,6 @@ def set_default_values
194194 end
195195
196196 def str_to_utf8 ( str )
197-
198197 CharlockHolmes ::Converter . convert ( str , str_encoding ( str ) , 'UTF-8' )
199198 end
200199
You can’t perform that action at this time.
0 commit comments