TL;DR
config.sandbox_by_default = trueを設定していても、rails console --no-sandboxで sandbox モードを無効にして起動できる。- オプションは CLI フレームワークの Thor が生やしているので、
--skip-sandboxでも無効にできた。
背景
Rails で config.sandbox_by_default = true を設定していると、rails console を実行したときに自動で --sandbox オプションが有効になる。これを無効にして起動したかった。
検証
Rails ガイドには、次のように書かれている。
sandbox モードを無効にして Rails コンソールを起動するには、
--no-sandboxを明示的に指定しなければなりません。
$ rails console --no-sandboxヘルプにも記載があった。
$ rails console -h
Usage:
bin/rails console
Options:
-e, [--environment=ENVIRONMENT]
-s, [--sandbox], [--no-sandbox]実際のコードを確かめようとしたが、no_sandbox や no-sandbox で検索しても、Rails のソースコードに定義が見つからなかった。Rails は Thor という CLI フレームワークを使っており、このオプションは Thor が生やしているようである。Thor の README には次のように書かれている。
All arguments can be set to nil (except required arguments), by supplying a no- or skip-variant. For example:
thor app name --no-attributes
そうであれば、--skip-sandbox でも無効にできるはずなので、試した。
$ rails console --skip-sandbox結果
--skip-sandbox でも sandbox モードを無効にできた。