0
我創建了一個rake任務,用於導入一個csv與smarter_csv gem。無法使用smarter_csv運行rake任務
拋出下面的消息,我加了整個的錯誤代碼,如果有幫助:
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/[email protected]_app/gems/smarter_csv-1.1.4/lib/smarter_csv/smarter_csv.rb:223:in `ensure in process'
/home/my_user/.rvm/gems/[email protected]_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/[email protected]_app/bin/ruby_executable_hooks:15:in `eval'
/home/my_user/.rvm/gems/[email protected]_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/[email protected]_app/gems/smarter_csv-1.1.4/lib/smarter_csv/smarter_csv.rb:23:in `initialize'
/home/my_user/.rvm/gems/[email protected]_app/gems/smarter_csv-1.1.4/lib/smarter_csv/smarter_csv.rb:23:in `open'
/home/my_user/.rvm/gems/[email protected]_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/[email protected]_app/bin/ruby_executable_hooks:15:in `eval'
/home/my_user/.rvm/gems/[email protected]_app/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => import_csv:import_csv
(See full trace by running task with --trace)
這是rake任務代碼:
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
這是整個堆棧跟蹤? – phoet