Skip to content

Instantly share code, notes, and snippets.

@sugumura
Created July 19, 2018 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sugumura/221d1f939c375b6641af587420824d87 to your computer and use it in GitHub Desktop.
Save sugumura/221d1f939c375b6641af587420824d87 to your computer and use it in GitHub Desktop.
Rails consoleでJSONを出力したいとき
# ファイルに書き出したい
>> f = File.new(Rails.root + 'hoge.json', 'w')
>> f << JSON.pretty_generate(Post.all.as_json)
>> f.close
# 出力したい
>> puts JSON.pretty_generate(Post.all.as_json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment