Skip to content

Error if csv file consists empty columns #197

@AlexeyKasianenko

Description

@AlexeyKasianenko

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions