简体   繁体   English

在本地文件系统而不是heroku上写入文件的rake任务

[英]rake task that writes to file on local filesystem and not heroku

I would like a rake task that gets some information and then writes to the local filesytem 我想要一个rake任务,该任务会获取一些信息,然后将其写入本地文件系统

I thought I had this working but not sure how. 我以为我有这个工作,但不确定如何。

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

and then call like 然后像

heroku run rake arc:vday

But this is not working and gives me an error on writing the file. 但这不起作用,并且在写入文件时给我一个错误。 Is there a workaround to make it write to my local filesystem and not heroku? 有没有变通办法可以使其写入本地文件系统而不是heroku?

Can you try this 你可以试试这个吗

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

instead of 代替

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM