Template to get rails apps started
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
Matt Brictson 2b3603edd9
Simplify CI used to test the template
4 years ago
.circleci Simplify CI used to test the template 4 years ago
app Upgrade to webpacker 5 4 years ago
bin Don't swallow command output 4 years ago
circleci Switch to new cimg/ruby docker image for CI 4 years ago
config Fix RuboCop rule violation for STDOUT 4 years ago
lib Auto launch web browser when starting puma 4 years ago
test Switch to new cimg/ruby docker image for CI 4 years ago
Gemfile.tt Remove unnecessary pins 4 years ago
Guardfile Remove asset pipeline customizations 4 years ago
LICENSE Happy New Year! 🥳 4 years ago
Procfile Add a reasonable default Procfile 6 years ago
Procfile.dev -C config/sidekiq.yml is the default and redundant 4 years ago
README.md Remove better_errors, stick with web-console 4 years ago
README.md.tt Chromedriver is installed automatically by webdrivers gem 4 years ago
Rakefile.rb Default rake task should fail if lint fails 4 years ago
config.ru.rb Improve Docker support by changing HOSTNAME var (#22) 5 years ago
editorconfig Makefile requires tabs, not spaces 4 years ago
eslintrc.js Remove eslint-plugin-jest; we don't include jest yet 4 years ago
example.env.tt SECRET_KEY_BASE is not needed in dev or test 4 years ago
gitignore Use dotenv for local development only 4 years ago
overcommit.yml Lint JS and CSS in app/components directory 4 years ago
prettierrc.js Format with latest Prettier 4 years ago
rubocop.yml.tt Include more files in rubocop checks 4 years ago
ruby-version.tt Initial public commit 9 years ago
stylelintrc.js Relax some stylelint rules 4 years ago
template.rb Remove eslint-plugin-jest; we don't include jest yet 4 years ago

README.md

mattbrictson/rails-template

Circle

Description

This is the application template that I use for my Rails 6 projects. As a freelance Rails developer, I need to be able to start new projects quickly and with a good set of defaults. I've assembled this template over the years to include best-practices, tweaks, documentation, and personal preferences, while still generally adhering to the "Rails way".

For older versions of Rails, use these branches:

Requirements

This template currently works with:

  • Rails 6.0.x
  • Bundler 2.x
  • PostgreSQL
  • chromedriver

If you need help setting up a Ruby development environment, check out my Rails OS X Setup Guide.

Installation

Optional.

To make this the default Rails application template on your system, create a ~/.railsrc file with these contents:

-d postgresql
-m https://raw.githubusercontent.com/mattbrictson/rails-template/main/template.rb

Usage

This template assumes you will store your project in a remote git repository (e.g. Bitbucket or GitHub) and that you will deploy to a production environment. It will prompt you for this information in order to pre-configure your app, so be ready to provide:

  1. The git URL of your (freshly created and empty) Bitbucket/GitHub repository
  2. The hostname of your production server

To generate a Rails application using this template, pass the -m option to rails new, like this:

rails new blog \
  -d postgresql \
  -m https://raw.githubusercontent.com/mattbrictson/rails-template/main/template.rb

Remember that options must go after the name of the application. The only database supported by this template is postgresql.

If youve installed this template as your default (using ~/.railsrc as described above), then all you have to do is run:

rails new blog

What does it do?

The template will perform the following steps:

  1. Generate your application files and directories
  2. Ensure bundler is installed
  3. Create the development and test databases
  4. Commit everything to git
  5. Push the project to the remote git repository you specified

What is included?

These gems are added to the standard Rails stack

  • Core
    • active_type for building simple and effective form/service objects
    • sidekiq Redis-based job queue implementation for Active Job
  • Configuration
    • dotenv for local configuration
  • Utilities
    • annotate auto-generates schema documentation
    • autoprefixer-rails automates cross-browser CSS compatibility
    • amazing_print try ap instead of puts
    • guard runs tests as you develop; mandatory for effective TDD
    • rubocop enforces Ruby code style
  • Security
  • Testing
    • shoulda shortcuts for common ActiveRecord tests

Postmark

I like to use Postmark for transactional email, and so I've included the postmark-rails gem and configured it in environments/production.rb. Make sure to sign up for a Postmark account to get an API key, or switch to your own preferred email provider before deploying your app.

Other tweaks that patch over some Rails shortcomings

  • A much-improved bin/setup script
  • Log rotation so that development and test Rails logs dont grow out of control

How does it work?

This project works by hooking into the standard Rails application templates system, with some caveats. The entry point is the template.rb file in the root of this repository.

Normally, Rails only allows a single file to be specified as an application template (i.e. using the -m <URL> option). To work around this limitation, the first step this template performs is a git clone of the mattbrictson/rails-template repository to a local temporary directory.

This temporary directory is then added to the source_paths of the Rails generator system, allowing all of its ERb templates and files to be referenced when the application template script is evaluated.

Rails generators are very lightly documented; what youll find is that most of the heavy lifting is done by Thor. The most common methods used by this template are Thors copy_file, template, and gsub_file. You can dig into the well-organized and well-documented Thor source code to learn more.