Search code examples
ruby-on-railsrakesmartercsv

unable to run rake task with smarter_csv


I created a rake task for import a csv with smarter_csv gem.

Throws the following message, i added the entire error code if it helps:

rake import_csv:import_csv
Digest::Digest is deprecated; use Digest
I, [2017-03-01T11:46:08.551994 #7029]  INFO -- : ** [Raven] Raven 0.14.0 configured not to send errors.
rake aborted!
NoMethodError: undefined method `close' for nil:NilClass
/home/my_user/.rvm/gems/ruby-2.1.1@my_app/gems/smarter_csv-1.1.4/lib/smarter_csv/smarter_csv.rb:223:in `ensure in process'
/home/my_user/.rvm/gems/ruby-2.1.1@my_app/gems/smarter_csv-1.1.4/lib/smarter_csv/smarter_csv.rb:223:in `process'
/home/my_user/my_app/lib/tasks/import_csv.rake:7:in `block (2 levels) in <top (required)>'
/home/my_user/.rvm/gems/ruby-2.1.1@my_app/bin/ruby_executable_hooks:15:in `eval'
/home/my_user/.rvm/gems/ruby-2.1.1@my_app/bin/ruby_executable_hooks:15:in `<main>'
Errno::ENOENT: No such file or directory @ rb_sysopen - /csv_imports/pacientes.csv
/home/my_user/.rvm/gems/ruby-2.1.1@my_app/gems/smarter_csv-1.1.4/lib/smarter_csv/smarter_csv.rb:23:in `initialize'
/home/my_user/.rvm/gems/ruby-2.1.1@my_app/gems/smarter_csv-1.1.4/lib/smarter_csv/smarter_csv.rb:23:in `open'
/home/my_user/.rvm/gems/ruby-2.1.1@my_app/gems/smarter_csv-1.1.4/lib/smarter_csv/smarter_csv.rb:23:in `process'
/home/my_user/my_app/lib/tasks/import_csv.rake:7:in `block (2 levels) in <top (required)>'
/home/my_user/.rvm/gems/ruby-2.1.1@my_app/bin/ruby_executable_hooks:15:in `eval'
/home/my_user/.rvm/gems/ruby-2.1.1@my_app/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => import_csv:import_csv
(See full trace by running task with --trace)

This is the code on the rake task:

namespace :import_csv do
  desc "import csv file"
  task import_csv: :environment do
    require 'smarter_csv'
    filename = '/csv_imports/file.csv'
    options = {:key_mapping => { :downcase_header => true }}
    SmarterCSV.process(filename, options) do |array|
      CsvImports.create( array.first )
    end
  end

end

Solution

  • This solved just witha dot. route issue.

     ./csv_imports/file.csv