LoginSignup
37
41

More than 5 years have passed since last update.

Railsのファイル入出力に関して

Posted at

単純にrubyでのファイル入出力を応用します

まずはファイルへの書き込み

f = File.open('file.txt', 'w') # wは書き込み権限
f.puts test
f.close

デフォルトだと
application/
/app
/db
/config
/file.txt

の位置に出来るので,
好みで

f = File.open('./app/assets/file.txt', 'w')

のようにするのがオススメ

読み込みは
wを
r
にするだけ!

37
41
2

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
37
41