Roo con rails4 dando método indefinido '[]' para nil: NilClass

Estoy tratando de importar archivos CSV y Excel en un proyecto de rails 4 (con validación) usando la gema Roo, basada enhttp://railscasts.com/episodes/396-importing-csv-and-excel.

He realizado algunos cambios para tener en cuenta Rails4 en lugar de Rails3 y los cambios en Roo, y mi modelo de ProjectImporter ahora se ve así:

class ProductImport
  include ActiveModel::Model
  attr_accessor :file

  def initialize(attributes = {})
    attributes.each { |name, value| send("#{name}=", value) }
  end

  def persisted?
    false
  end

  def save
    if imported_products.map(&:valid?).all?
      imported_products.each(&:save!)
      true
    else
      imported_products.each_with_index do |product, index|
        product.errors.full_messages.each do |message|
          errors.add :base, "Row #{index + 2}: #{message}"
        end
      end
      false
    end
  end

  def imported_products
    @imported_products ||= load_imported_products
  end

  def load_imported_products
    spreadsheet = open_spreadsheet
    spreadsheet.default_sheet = spreadsheet.sheets.first
    puts "!!! Spreadsheet: #{spreadsheet}"
    header = spreadsheet.row(1)
    (2..spreadsheet.last_row).map do |i|
      row = Hash[[header, spreadsheet.row(i)].transpose]
      product = Product.find_by(id: row['id']) || Product.new
      product.attributes = row.to_hash.slice(*['name', 'released_on', 'price'])
      product
    end
  end

  def open_spreadsheet
    case File.extname(file.original_filename)
      when ".csv" then
        Roo::CSV.new(file.path, ,nil)
      when '.tsv' then
        Roo::CSV.new(file.path, csv_options: { col_sep: "\t" })
      when '.xls' then
        Roo::Excel.new(file.path, nil, :ignore)
      when '.xlsx' then
        Roo::Excelx.new(file.path, nil, :ignore)
      when '.ods' then
        Roo::OpenOffice.new(file.path, nil, :ignore)
      else
        raise "Unknown file type #{file.original_filename}"
    end
  end
end

Cuando intento ejecutar una importación (usando datos CSV de prueba), falla enheader = spreadsheet.row(1) con el errorundefined method '[]' for nil:NilClass. El extraputs declaración que he incluido confirma quespreadsheet en sí mismo no es nulo: da!!! Spreadsheet: #<Roo::CSV:0x44c2c98>. Pero si trato de llamar a casi cualquiera de los métodos esperados, como#last_row, me da el mismo error de método indefinido.

Entonces, ¿qué estoy haciendo mal?

Respuestas a la pregunta(1)

Su respuesta a la pregunta