Skip to main content

Joyful Rails

Published: Jul 28th, 2020
Updated: Dec 29th, 2020

Introduction

I love Ruby on Rails. I think it’s a fantastic framework for web applications. I highly recommend it and I thoroughly enjoy working with it.

I’ve been lucky enough to work extensively with Rails on many different projects over many different years. Most Rails development, like most software development, happens on long-lived projects. A well-established and well-configured project is an absolute joy to work in and collaborate on.

But a new Rails project doesn’t have many of the little tweaks and additions that make things so nice for me. I end up spending a lot of time and frustration repeating the same steps in every application.

This guide is an effort to make those steps faster and easier. The goal is to create a smooth and rapid path from zero to a codebase I love working in.

What This Is Not

This is not a beginner’s guide

I will explain things as simply as I can, but there will likely be some important information left out. If you do not understand a recommendation, you might not understand the consequences.

This is not something to apply blindly

Examine every bit of the advice herein to see if it is right for you, your project, and your team before applying it. That’s what the annotations are for.

This is not static

The world changes and I change with it. My preferences and recommendations are in constant flux. This guide will change with them.

This is not an automated setup script

There is no point in automating something that will change every time you do it.

If you want an automated setup script, take a look at Suspenders. It is a Rails template created by Thoughtbot with their standard defaults. They make a lot of good choices, some of which I will certainly draw from.

Table of Contents

0 Joyful Rails

A guide to make working with your Rails application more productive and joyful.

1 Ruby Version Management

Use the right version of Ruby for the job.

2 The Rails New Command

Creating a brand new Rails application.

3 Git Initialization

Use version control to make changes with confidence.

4 No Git Masters

Remove problematic language from your Git setup.

5 Pairs File

Accurately record changes made while pairing by adding multiple authors to your commits.

6 Add a License

If your code is open source, make sure people know.

7 Adopt a Code of Conduct

Ensure a safe and welcoming environment by adopting a code of conduct.

8 Switch to PostgreSQL

Switch over to a production-ready database.

9 Remove Gem Version Specifiers

Make it easy to continuously keep your libraries up to date.

10 Switch to HAML

Make your HTML templates easier to work with.

11 Switch to Sass

Make your cascading style sheets easier to work with.

12 Switch to RSpec

Use a clear and expressive testing framework.

13 Add RSpec::Its

Make it easier to test object attributes.

14 Configure Generators

Make the Rails generators generate the code you want. No more, no less.

15 Switch to UUIDs

Database keys that can’t be guessed, don’t overflow, and don’t leak information.

16 Use a Ruby Linter

Make your Ruby style consistent.

17 My Ruby Style

Make your Ruby style beautiful.

18 Use a Rails Linter

Avoid common Rails mistakes and correct them automatically.

19 Library Vulnerability Checks

Find security issues in your libraries before the bad guys do.

20 Code Vulnerability Checks

Find security issues in your code before the bad guys do.

21 Use a License Monitor

Avoid using libraries with licenses you do not want to agree to.

22 Default Rake Task

Run all of your automated checks with a single command.

23 Set Up a Production Environment

Deploy your Rails application.

24 Update the Readme

What do future developers need to know? What do you need to tell them?

25 Add Authentication

Identify your users.

26 Add an Authorization Library

Identify what users can do.

27 Add a CSS Framework

Make it easy to make your interface beautiful.