[RUBY] Minimal Rails with reduced file generation


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.

Rails new options

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.

Specifying the database used

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.

Exclusion of minitest

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.

Exclusion of turbolinks

rails new sample_app --skip-turbolinks

Replace page transitions with Ajax and no longer include turbolinks, which skips JavaScript and CSS parsing to speed things up. Since turbolinks has problems such as ready not firing, it seems that some people exclude it.

Exclusion of .gitignore

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.

API mode

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.

Settings after Rails new

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

This is just an example, but you can significantly reduce the amount of files by making these settings.

At the end

I just added a few simple options, but it helped me a lot in my comfortable development.

Articles that I used as a reference

Touch Rails 5 API mode Prevent rails generate from generating extra files

Recommended Posts

Minimal Rails with reduced file generation
[Rails] Benefit from rubycop with minimal effort
Rails deploy with Docker
[Rails 6] RuntimeError with $ rails s
Handle devise with Rails
[Rails] Learning with Rails tutorial
[Rails] Test with RSpec
[Rails] Development with MySQL
Supports multilingualization with Rails!
Double polymorphic with Rails
csv file output with opencsv
Introduced graph function with rails
[Rails] Express polymorphic with graphql-ruby
[Rails] Upload videos with Rails (ActiveStorage)
Try using view_component with rails
[Vue Rails] "Hello Vue!" Displayed with Vue + Rails
Japaneseize using i18n with Rails
iOS: File upload with SFTP
API creation with Rails + GraphQL
Preparation for developing with Rails
File upload with Spring Boot
Generation gap with new engineers
[rails] Deleted NOFILE migration file
Run Rails whenever with docker
[Docker] Rails 5.2 environment construction with docker
Use multiple databases with Rails 6.0
[Rails] Specify format with link_to
Login function implementation with rails
[Rails] Delete the migration file
[Docker] Use whenever with Docker + Rails
I want to hook log file generation / open with log4j # FileAppender
Try to make a cross-platform application with JRuby (jar file generation)