【问题标题】:rake task that writes to file on local filesystem and not herokurake 任务写入本地文件系统上的文件而不是 heroku
【发布时间】:2015-01-21 04:27:39
【问题描述】:

我想要一个获取一些信息然后写入本地文件系统的 rake 任务

我以为我有这个工作,但不知道如何。

namespace :arc do
  task :vday => :environment do
    locations=Location.with_current_mec "something"
    jt={}
    jt[:locations]={}
    locations.each do |location|
      jt[:locations][location.id]=location.to_small_hash
    end
    # want this to write to local filesytem
    File.write('/Users/jt/output.json', JSON.pretty_generate(jt))
  end
end

然后像这样调用

heroku run rake arc:vday

但这不起作用,并且在写入文件时出现错误。有没有办法让它写入我的本地文件系统而不是heroku?

【问题讨论】:

    标签: ruby-on-rails heroku rake


    【解决方案1】:

    你可以试试这个

    File.open('/Users/jt/output.json', 'w') {|file| file.write(JSON.pretty_generate(jt))}
    

    而不是

    File.write('/Users/jt/output.json', JSON.pretty_generate(jt))
    

    【讨论】:

      猜你喜欢
      • 2015-04-13
      • 2018-01-28
      • 1970-01-01
      • 1970-01-01
      • 2016-02-24
      • 2014-04-30
      • 1970-01-01
      • 2017-06-08
      • 1970-01-01
      相关资源
      最近更新 更多