Sunday, April 24, 2016

How I create my Rails projects

This is more like a note-to-self, but hopefully it might be helpful to someone.

Updated 2020-09-06.

Rails Version

First I make sure I am running the correct version of Rails, as it affects files created by the generator.

If I'm working with the latest stable version, I update Rails before doing anything else:

gem update rails
rails -v

Project Creation

There are a few components that come by default in Rails that I do not use in my projects. Namely:
  • Anything non-API related
  • Test Unit
  • Spring
  • Action Mailbox
  • Action Cable
So I disable then when creating my Rails app for the first time, just so I don't have to remove references later.

API

I only create APIs in Rails these days, so I don't need any frontend-oriented features. This includes all Javascript, Turbolinks, helpers, and so on.

--api

Test Unit

I've been a fan of RSpec since I started working with tests, so I avoid creating a Rails project with Test Unit files. 

-T

Spring

Another gem I had issues in the past, so I'd rather remove potential annoyances. (YMMV.) Its premise is good, but it may work poorly with gems that have different autoload rules (such as ActiveAdmin). The option is:

--skip-spring

Other Options

Action Mailbox is removed with --skip-action-mailbox.
Action Cable is removed with -C.

I also don't like bundle install running after I create my app, so I add the -B option to the command as well. After creating the project, I manually inspect the Gemfile and add/remove gems as I see fit before installing them for the first time.

Final Command

rails new <project-name> --api -B -T -C --skip-spring