When I tried to create a new app with Rails, I was worried that an extra file would be generated, so this time I will write a method and setting to do rails new with the minimum file generation that I need.
By adding an option to rails new, the app will be created without generating the specified related files. Below are some of the options you might use most often. Some of them are not file generation.
rails new sample_app --database=mysql
--database = (arbitrary DB) will create an application with the DB specified from the beginning. If not specified, it should be sqlite. Of course, you can change the DB later, but it's a little troublesome, so if you have decided which DB to use, specify it first.
rails new sample_app --skip-test
Rails will no longer generate the standard minitest. This is a sure option when using Rspec. There are other skip options as well.
rails new sample_app --skip-turbolinks
rails new sample_app --skip-git
It will no longer generate the default gitignore. It is used when gitignore is prepared by deciding the file not to push in advance.
rails new sample_app --api
It will be created with a small configuration when creating an application as an API. It feels like the V of MVC is gone. The default gem is also significantly reduced. For details, please refer to the reference article at the end.
You can easily create a controller or model by using rails generate, but at the same time, you may generate unnecessary helpers and tests. In such a case, describe the setting of the generate command in application.rb of config.
module Sample class Application < Rails::Application config.generators do |g| g.stylesheets false #stylesheets are no longer automatically generated g.helper false #helper is no longer automatically generated g.test_framework false #test and fixture are no longer generated end end end
This is just an example, but you can significantly reduce the amount of files by making these settings.
I just added a few simple options, but it helped me a lot in my comfortable development.
Touch Rails 5 API mode Prevent rails generate from generating extra files