We have 2 situation when raised errors without handling:
Empty CSV and model has force_encoding: 'auto'
In this case encoding detected automatically by
def dynamic_encoding(data)
CharDet.detect(data)['encoding']
end
But if data is empty string '' result will be nil. data.force_encoding(encoding_name) where data is empty string and encoding_name is nil raise TypeError: no implicit conversion of nil into String
When we have invalid csv in which values exceeded headers activerecord_import gem raised ArgumentError:
raise ArgumentError, "Number of values (#{arr.length}) exceeds number of columns (#{columns.length})"
We can handle it in collection_action and return flash message to users
We have 2 situation when raised errors without handling:
Empty CSV and model has force_encoding: 'auto' In this case encoding detected automatically by
But if data is empty string '' result will be nil.
data.force_encoding(encoding_name)
wheredata is empty string and encoding_name is nil
raise TypeError: no implicit conversion of nil into StringWhen we have invalid csv in which values exceeded headers activerecord_import gem raised ArgumentError:
We can handle it in collection_action and return flash message to users