簡體   English   中英

在本地文件系統而不是heroku上寫入文件的rake任務

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

我想要一個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?

你可以試試這個嗎

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

代替

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM