LoginSignup
5
2

More than 5 years have passed since last update.

HerokuでTempfileを使う

Posted at

パスの指定と、ディレクトリを作成することがポイント。
まず、Tempfileのデフォルトパスでは作れないのでパスを指定して作ることにする
Herokuではtmpもしくはlogsにだけ書き込める

temp_file = Tempfile.new(prefix, Rails.root.join('tmp'))

さらにRails.root.join('tmp')は自動で作成されないので、チェックしてない場合は作成する必要がある。

temp_dir = Rails.root.join('tmp')
Dir.mkdir(temp_dir) unless Dir.exists?(temp_dir)

参考

No such file or directory error with ruby tempfile and heroku cedar | kulehandluke

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2