Skip to content

davetron5000/rails-app-template-sustainable

Repository files navigation

rails-app-template-sustainable

This is a Rails Application Template that will create a Rails app set up similarly to the one outlined in Sustainable Web Development with Ruby on Rails.

This is for Rails 6.1 only!

To use

From The Internets

bin/rails new my-app \
    --skip-bundle \
    --skip-turbolinks \
    --skip-spring \
    --skip-listen \
    --database=postgresql \
    --template=https://raw.githubusercontent.com/davetron5000/rails-app-template-sustainable/main/template.rb

Locally

git clone https://github.com/davetron5000/rails-app-template-sustainable
rails new my-app \
      --rc=rails-app-template-sustainable/.railsrc \
      --template=rails-app-template-sustainable/template.rb

What you get

In particular:

  • Gems:
    • Removes Gems that cause problems:
      • Turbolinks makes your app feel slow and broken
      • Spring creates an unstable development environment
    • Gems for better testing:
      • Factory Bot to manage test data
      • Faker to provide fake values for that data
      • minitest-reporters to get more useful test run output
    • Gems for development:
      • dotenv-rails to allow management of local UNIX environments
      • foreman to run multiple processes locally
    • Gems for managing security issues:
      • Brakeman
      • bundler-audit
    • Gems for better production behavior:
      • lograge for single-line logging
      • sidekiq for background jobs
      • Postgres
  • Dev Workflow
    • bin/setup that does a more involved setup
    • bin/ci runs all quality checks (tests, brakeman, bundle audit, yarn audit)
    • bin/run runs the app locally
    • bin/sql get a SQL prompt to your local database
    • bin/db-{migrate,rollback} - migrate and rollback both dev and test in one command
    • bin/release - Release phase script for Heroku to run migrations
  • Other Things
    • Removes config/database.yml and config/secrets.yml because your app will get all configuration from ENV
    • SQL-based schema management so you can use any feature of Postgres you like
    • No stylesheets or helpers generated by generators since they provide a false sense of modularity that is of zero benefit.
    • A simple base ApplicationService and a service class generator bin/rails g service MyThing to encourage putting code in app/services
    • All datetime fields in migrations uses timestamp with time zone which is the proper type in Postgres.
    • A method confidence_check to allow validating assumptions in tests separate from asserting code behavior.
    • A method not_implemented! to allow skipping a test you have not implemented
    • A test to lint all your factories

FAQ

Literally no one has asked me questions, but here are a few

  • Spring works though right?
    • It creates an unstable development environment that manifests as odd and hard-to-diagnose behavior. It will sap the time and resources of more tenured engineers on your team. It is not worth it.
    • This behavior is not how I would define "works".
  • Turbolinks makes my site feel…slower?
    • Because Turbolinks does not provide any loading animations or progress, any controller method that responds in less than 100ms (including network round trip) will make your app appear broken and slow, because it breaks the cognitive link between clicking a link and seeing something happen. A controller that takes 1 second to respond when Turbolinks is not enabled will feel faster and more reliable because the browser responds instantly. This should be the default behavior of your app and you should control when and how you want to optimize page performance.
  • But I don't want (or can't) use Postgres!
    • Sorry about that. This template assumes you are using Postgres.
  • I want to use RSpec!
    • I'm not stopping you from doing that. You can install RSpec and run its generator and get rid of minitest if you like. It won't make much difference to the success of your project, but it's cool. Go for it.
  • Some other gems should be listed here
    • I only want stuff you would need pretty much always, and that implies a small list of gems. I also want to be careful about gem debt, because each dependency you add is a carrying cost.

About

A Rails App Template that creates a new Rails app according to the sustainable rails book

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published