无法使用 smarter_csv 运行 rake 任务 [英] unable to run rake task with smarter_csv

查看:48
本文介绍了无法使用 smarter_csv 运行 rake 任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个使用 smarter_csv gem 导入 csv 的 rake 任务.

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)

这是rake任务的代码:

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

推荐答案

这只需一个点就解决了.路线问题.

This solved just witha dot. route issue.

 ./csv_imports/file.csv

这篇关于无法使用 smarter_csv 运行 rake 任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆