LoginSignup
3
0

More than 3 years have passed since last update.

Rails6 のちょい足しな新機能を試す92(config.disable_sandbox 編)

Posted at

はじめに

Rails 6 に追加された新機能を試す第92段。 今回は、 config.disable_sandbox 編です。
Rails 6 では、 rails console --sandbox を実行したときに、エラーメッセージを表示して終了するオプション config.disable_sandbox が追加されました。
本番環境などで、 rails console --sandbox したときにトランザクションログが大きくなりすぎて、メモリが不足してサービスがダウンしてしまうことを防ぐ目的で導入されたようです。

Ruby 2.6.4, Rails 6.0.0 で確認しました。

$ rails --version
Rails 6.0.0

プロジェクトを作る

$ rails new rails_sandbox
$ cd rails_sandbox

config.disable_sandbox を設定する

今回は、 config/environments/development.rb で設定します。

config/environments/development.rb
Rails.application.configure do
  ...
  config.disable_sandbox = true
end

rails console を実行する

--sandbox オプションつきで、 rails console を実行してみます。

$ bin/rails c --sandbox
Running via Spring preloader in process 48
Error: Unable to start console in sandbox mode as sandbox mode is disabled (config.disable_sandbox is true).

エラーメッセージが表示されて実行できないことが確認できます。

試したソース

試したソースは以下にあります。
https://github.com/suketa/rails_sandbox/tree/try092_console_sandbox

参考情報

3
0
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
3
0