DEV Community

koki-takishita
koki-takishita

Posted on

3 3

rails generators 制限設定

rails g コマンドで生成されるファイルを制限する

config/application.rb内に下記のように設定する

config.generators do |g|
  g.jbuilder       false
end
 # p config.generators
Enter fullscreen mode Exit fullscreen mode
  • 各種設定項目はドキュメント内で確認できた Rails::Generators Image from Gyazo
  • コード①を有効化して、サーバログを確認すると下記のように設定項目を確認できる Image from Gyazo

ドキュメントに記述されていない項目...

わからなかったこと
  • ルーティング生成の有無の設定項目であるskip_routesは、railsガイドAPIドキュメントその他の公式と思われるリソースを調べたが見つからず個人ブログなどの2次、3次などのリソースでしか知ることができなかった。
分かったこと

railsのリポジトリにて、Rails::ControllerGenerator::ControllerGeneratorオブジェクトclass_optionの引数にskip_routesが記述されていることを確認できた。上記のコードとどのように絡んでくるかはわかっていないが、skip_routes true or falseを記述することで、rails g controller実行の際に設定を読み込み、config.generators.skip_routes falseならば、ルーティング生成を無効にするという動きをすると思われる。

感想

APIドキュメントなどの公式リソースから情報を読み取っているが、もし公式リソースに情報がない、もしくは見つけられない時の調べ方に課題を感じた。

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More