Limit files created with the rails g controller command

Development environment

rails 6.0.3 (Assuming a project that does not use * Minitest *)

Description

rails g controller <controller name> <action name> Will create ** unnecessary files ** in addition to controller and view.

To avoid this, create the following files in the rails project, When executing the rails g controller command ** Prevent files other than controller and view from being created **.

config/initializers/generators.rb


Rails.application.config.generators do |g|
  g.assets false
  g.helper false
  g.skip_routes true
end

If creating the above file is troublesome, Execute the rails g controller command with the following three options added.

Terminal


rails g controller <Controller name> <Action name> --no-assets --no-helper --skip-routes

The above has the following merits. -** stylesheets files are not created under ʻapp / assets / **. -** Helper file is not created under ʻapp / helpers / . - Routing is not added to config / routes.rb **.

Recommended Posts

Limit files created with the rails g controller command
[Rails] Put together the same code with controller actions
Why can I use the rails command installed with gem? ??
[Rails / Routing] How to refer to the controller in the directory you created
I got a warning message with the rails _6.0.3_ new hello_myapp command
Create a jar file with the command
Rails: 7 basic actions defined on the controller
[Ruby on Rails] model, controller terminal command
Prepare the format environment with "Rails" (VScode)
[Ruby on Rails] Controller test with RSpec
Ruby on Rails controller create / delete command
Check the processing contents with [rails] binding.pry
I rewrote the Rails tutorial test with RSpec
Downgrade an existing app created with rails 5.2.4 to 5.1.6
Publish the app made with ruby on rails
Understanding the MVC framework with server-side Java 3/4 Controller
rails new app is not created with app name
Implement the Like feature in Ajax with Rails.
Rails development environment created with VSCode and devcontainer
Get data with api created by curl command
Determine the current page with Ruby on Rails
Try to summarize the common layout with rails
When importing CSV with Rails, it was really easy to use the nkf command