2015-01-21 104 views
1

我想耙的任務,得到了一些信息,然後寫入本地filesytemrake任務

我想我有這個工作,但不知道如何。

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?

回答

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))