Skip to content

Error if csv file consists empty columns #197

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

Activity

  1. added a commit that references this issue on Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions