Options for rails new and settings to be done after rails new

As a memorandum, I will summarize the options that I personally feel "don't use often when doing rails new "and the settings that are often made when creating a new project.

Options when doing rails new

First of all, about the options that are often added when doing rails new. Each option will be described later.

rails _6.0.3.2_ new appname --database=mysql --skip-test

Rails version specification

rails _6.0.3.2_ new

This will allow you to specify the version of rails. Please change the value of _6.0.3.2_ each time.

Specifying the database to use

--database=mysql

If you don't specify a DB like this, the default DB will be sqlite. This time it is a setting to use mysql.

Do not generate Minitest

--skip-test

When you generate a project by default, a Minitest is created. I myself often use RSpec for testing, so I try not to generate a Minitest as described above.

Settings to be done after rails new

From here, it will be the setting after actually doing rails new.

Set not to generate unnecessary files when using the rails g command

config/application.rb


module appname
  class Application < Rails::Application
    #Add the following
    config.generators do |g|
      g.stylesheets false
      g.javascripts false
      g.helper false
      g.test_framework false
    end
    config.time_zone = "Tokyo"
    config.i18n.default_locale = :ja
  end
end

The following parts were mainly added this time.

config.generators do |g|
  g.stylesheets false
  g.javascripts false
  g.helper false
  g.test_framework false
end

If you create a controller with the rails g command, the file will be generated automatically, but this description is to prevent unnecessary things (coffee and css) from being generated. The rails g command is something you use a lot during the development process, so it's a lot easier to do this first.

config.time_zone = "Tokyo"
config.i18n.default_locale = :ja

Also, here we will set the default language to Japanese and the time zone default to Tokyo.

config.i18n.default_locale = :ja

However, there is a caution about the above (Japanese localization), and an error may occur when accessing ʻusers / sign_up` when using the devise Gem. So, if you think "Is it okay to translate it into Japanese now? I'm tired of getting an error", I think that you don't have to make any special settings here.

Recommended Posts

Options for rails new and settings to be done after rails new
Rails tutorial When rails new cannot be done due to different versions
[Rails] Rails new cannot be done from Docker
Introducing the settings and reference articles that are first done in Rails new development
[Rails] Prepare dummy data to be used for testing [Faker]
[Swift 5] Processing and precautions for transitioning to the iOS settings app
Rails new fails to install mysql
[Rails] How to add new pages
[Rails] Validation settings and Japanese localization
Settings that should be done when operating a production environment with Rails
[Docker] How to create a virtual environment for Rails and Nuxt.js apps
(For beginners) [Rails] Time saving tech! How to install and use slim
[Rails 6] cocoon_ Add id and data attributes to the form to be added
[Rails] Articles for beginners to organize and understand the flow of form_with
Install Webpacker and Yarn to run Rails
[For rails beginners] Specify transition destination after logging in to multiple Devise models