· Ruby · 7 min read
Rails new options
Let's see the official way to create Rails application, as well as the minimalistic option.
How to create a new Rails app
At the time of writing, current Rails version is 8.
You can also follow the Rails new official guide.
Let’s see the default way to create a new Rails app.
It will create a default new app with 21 gems included. The installation process will last a few minutes. Amongst other things, it will create files, directories, and run a first webpack-based compilation.
Prerequisite : ruby, bundler, rails, node, and yarn must be installed.
Just run :
$> rails new myapp
And go for a coffee break ☕
List of all available options
To list all available options, simply run rails new —help. As the time of writing (Rails 6.1.3) it will output :
Usage:
rails new APP_PATH [options]
Options:
[--skip-namespace] # Skip namespace (affects only isolated engines)
# Default: false
[--skip-collision-check] # Skip collision check
# Default: false
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
# Default: /home/david/.asdf/installs/ruby/3.3.0/bin/ruby
-n, [--name=NAME] # Name of the app
-m, [--template=TEMPLATE] # Path to some application template (can be a filesystem path or URL)
-d, [--database=DATABASE] # Preconfigure for selected database
# Default: sqlite3
# Possible values: mysql, trilogy, postgresql, sqlite3, mariadb-mysql, mariadb-trilogy
-G, [--skip-git] # Skip git init, .gitignore and .gitattributes
[--skip-docker] # Skip Dockerfile, .dockerignore and bin/docker-entrypoint
[--skip-keeps] # Skip source control .keep files
-M, [--skip-action-mailer] # Skip Action Mailer files
[--skip-action-mailbox] # Skip Action Mailbox gem
[--skip-action-text] # Skip Action Text gem
-O, [--skip-active-record] # Skip Active Record files
[--skip-active-job] # Skip Active Job
[--skip-active-storage] # Skip Active Storage files
-C, [--skip-action-cable] # Skip Action Cable files
-A, [--skip-asset-pipeline] # Indicates when to generate skip asset pipeline
-J, --skip-js, [--skip-javascript] # Skip JavaScript files
[--skip-hotwire] # Skip Hotwire integration
[--skip-jbuilder] # Skip jbuilder gem
-T, [--skip-test] # Skip test files
[--skip-system-test] # Skip system test files
[--skip-bootsnap] # Skip bootsnap gem
[--skip-dev-gems] # Skip development gems (e.g., web-console)
[--skip-thruster] # Skip Thruster setup
[--skip-rubocop] # Skip RuboCop setup
[--skip-brakeman] # Skip brakeman setup
[--skip-ci] # Skip GitHub CI files
[--skip-kamal] # Skip Kamal setup
[--skip-solid] # Skip Solid Cache, Queue, and Cable setup
[--dev], [--no-dev], [--skip-dev] # Set up the application with Gemfile pointing to your Rails checkout
[--devcontainer], [--no-devcontainer], [--skip-devcontainer] # Generate devcontainer files
[--edge], [--no-edge], [--skip-edge] # Set up the application with a Gemfile pointing to the 8-0-stable branch on the Rails repository
--master, [--main], [--no-main], [--skip-main] # Set up the application with Gemfile pointing to Rails repository main branch
[--rc=RC] # Path to file containing extra configuration options for rails command
[--no-rc] # Skip loading of extra configuration options from .railsrc file
[--api], [--no-api], [--skip-api] # Preconfigure smaller stack for API only apps
# Default: false
[--minimal], [--no-minimal], [--skip-minimal] # Preconfigure a minimal rails app
-j, --js, [--javascript=JAVASCRIPT] # Choose JavaScript approach
# Default: importmap
# Possible values: importmap, bun, webpack, esbuild, rollup
-c, [--css=CSS] # Choose CSS processor. Check https://github.com/rails/cssbundling-rails for more options
# Possible values: tailwind, bootstrap, bulma, postcss, sass
-B, [--skip-bundle] # Don't run bundle install
[--skip-decrypted-diffs] # Don't configure git to show decrypted diffs of encrypted credentials
Runtime options:
-f, [--force] # Overwrite files that already exist
-p, [--pretend], [--no-pretend], [--skip-pretend] # Run but do not make any changes
-q, [--quiet], [--no-quiet], [--skip-quiet] # Suppress status output
-s, [--skip], [--no-skip], [--skip-skip] # Skip files that already exist
Rails options:
-h, [--help], [--no-help], [--skip-help] # Show this help message and quit
-v, [--version], [--no-version], [--skip-version] # Show Rails version number and quit
Description:
The `rails new` command creates a new Rails application with a default
directory structure and configuration at the path you specify.
You can specify extra command-line arguments to be used every time
`rails new` runs in the .railsrc configuration file in your home directory,
or in $XDG_CONFIG_HOME/rails/railsrc if XDG_CONFIG_HOME is set.
Note that the arguments specified in the .railsrc file don't affect the
default values shown above in this help message.
You can specify which version to use when creating a new rails application
using `rails _<version>_ new`.
Examples:
`rails new ~/Code/Ruby/weblog`
This generates a new Rails app in ~/Code/Ruby/weblog.
`rails _<version>_ new weblog`
This generates a new Rails app with the provided version in ./weblog.
`rails new weblog --api`
This generates a new Rails app in API mode in ./weblog.
`rails new weblog --skip-action-mailer`
This generates a new Rails app without Action Mailer in ./weblog.
Any part of Rails can be skipped during app generation.
Skip one or more features
If you want to skip one or more feature, for example, if you don’t want turbolinks nor system tests, run
$> rails new myapp --skip-turbolink --skip-system-test
If there are too many options you want to skip, below command will create an app according to options.
$> rails new myapp --rc=options
“options” here is a file that contains any flag you need.
Skip (almost) all features
There’s now a new way (since Rails 6.1) to create a minimalist Rails app. It build a new app in a few seconds, with only 7 gems (at the time of writing).
$> rails new myapp --minimal
Here is the Gemfile created :
source "https://rubygems.org"
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 8.0.0"
# The modern asset pipeline for Rails [https://github.com/rails/propshaft]
gem "propshaft"
# Use sqlite3 as the database for Active Record
gem "sqlite3", ">= 2.1"
# Use the Puma web server [https://github.com/puma/puma]
gem "puma", ">= 5.0"
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ windows jruby ]
# Use the database-backed adapters for Rails.cache and Active Job
gem "solid_cache"
gem "solid_queue"
# Deploy this application anywhere as a Docker container [https://kamal-deploy.org]
gem "kamal", require: false
# Add HTTP asset caching/compression and X-Sendfile acceleration to Puma [https://github.com/basecamp/thruster/]
gem "thruster", require: false
group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri windows ], require: "debug/prelude"
# Static analysis for security vulnerabilities [https://brakemanscanner.org/]
gem "brakeman", require: false
# Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/]
gem "rubocop-rails-omakase", require: false
end
It’s notably heavier than previous Rails version, solid_cache, solid_queue, kamal, and thruster being here by now.
Here is the list of what will NOT be included
- action_cable : integration of websockets into Rails.
- action_mailbox : integration of e-mail inbox behaviour into Rails controllers.
- action_mailer : send email with Rails.
- action_text : add the ability to put a HTML into Rails.
- active_job : add the ability to create background jobs
- active_storage : ability to upload files through 3rd party tools like AWS
- bootsnap : boot a Rails app faster
- jbuilder : build JSON response
- spring : boot a Rails app faster (like bootsnap, but differently…)
- system_tests : functional testing abilities
- turbolinks : now deprecated and replaced by Turbo. Allow a SPA-mode navigation once app is loaded in browser.
- webpack : the famous JavaScript bundler.
Why you should rely on fresh, new, minimalist Rails application
Using the flag —minimal has the following advantages :
You may reach a deep understanding of the default gems of your stack. Take time to understand the few gems already included, then you will (very more likely) take time to understand the one you added. To the contrary, if you create a new Rails app without the “—minimal” flag, the risk is to end up with some fear of not understanding what’s going on, plus some dead code, and annoying bugs - not caused by your code, but because of the frictions created by conflicting gems.
It’s very easy then to isolate a problem that arise in your daily production app. Just recreate another minimalist app, outside your repository, and put inside (maybe by copy/pasting) all files to recreate the bug you’re working on.
Take time to see if you need any of the feature listed above. Not all apps need to have the “e-mail inbox” features. Many developers skip the “spring” option. Maybe you will do some functional testing thanks to Cypress. Actually, chances that you Rails app looks like the default one is next to zero.
Summary
That was a quick recap about defaults for creating a new Rails app.