active_admin_import icon indicating copy to clipboard operation
active_admin_import copied to clipboard

Error if csv file consists empty columns

Open AlexeyKasianenko opened this issue 2 years ago • 0 comments

If csv file consists empty columns like this

,col_1,col_2,col_3,col_4,col_5,col_6
,1,112,1,100,130,4,8

it rases error Error: undefined method 'underscore' for nil:NilClass Possible solution is to change prepare_headers method in Importer class like this

  def prepare_headers
    headers = self.headers.present? ? self.headers : yield
    headers = headers.map(&:to_s)
    @headers = headers.zip(headers.map { |el| el.underscore.gsub(/\s+/, '_') }).to_h.with_indifferent_access
    @headers.merge!(options[:headers_rewrites].symbolize_keys.slice(*@headers.symbolize_keys.keys))
  end

AlexeyKasianenko avatar Mar 28 '23 18:03 AlexeyKasianenko