A starter blueprint to help fast track setting up a new Rails application. Simply go through the list below choosing the features and options you'd like to enable in your project, expand that section then run the template to install that functionality. It's as easy as that!
To get started, choose one of the following options.
Clone Repo
Replace my_app
with the name of your application.
git clone https://github.com/dalezak/rails-blueprint.git my_app
-or-
Download Repo
Download and extract https://github.com/dalezak/rails-blueprint/archive/refs/heads/main.zip into folder with the name of your application.
-or-
Follow Online
Instead of cloning or downloading the repo, you can also just follow these steps online.
Then move through the list below doing any of the sections your application needs. If you already have Rails setup, then skip the Setup Environment
section, or if you don't want Soft Deletes
just move past it.
Setup your local environment with Ruby, Rails and Node.
Install Ruby
Visit Rails > Getting Started > Installing Ruby for instructions on installing the Ruby language.
ruby -v
Install RVM
Visit RVM > Install for instructions on setting up RVM so you can easily switch between different version of Ruby.
rvm --default use 3.0.0
Install Node
Visit Rails > Getting Started > Installing Node for instructions on setting up Node and Yarn.
npm -v
yarn -v
Install Rails
Visit Rails > Getting Started for instructions on installing Rails framework.
gem install rails -v 7.0.0
rails -v
Install a local database.
Install Postgres
Visit Postgres > Download for instructions on installing Postgres database.
psql --version
-or-
Install SQLite3
Visit Rails > Getting_started > Installing SQLite for instructions on installing SQlite database.
Run rails new --help
to view all command options.
Postgres + Bootstrap + Esbuild
Creates a new Rails project with Postgres database, Bootstrap css and ESbuild javascript.
rails new . -s --git --database=postgresql --css=bootstrap --javascript=esbuild
Add the following section to your package.json
:
"scripts": {
"build": "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds",
"build:css": "sass ./app/assets/stylesheets/application.bootstrap.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules"
}
-or-
Postgres + Tailwind + Esbuild
Creates a new Rails project with Postgres database, Tailwind css and ESbuild javascript.
rails new . -s --git --database=postgresql --css=tailwind --javascript=esbuild
Add the following section to your package.json
:
"scripts": {
"build:css": "sass ./app/assets/stylesheets/application.bootstrap.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules"
}
-or-
Postgres + Bootstrap + Webpack
Creates a new Rails project with Postgres database, Bootstrap css and Webpack javascript.
rails new . -s --git --database=postgresql --css=bootstrap --javascript=webpack
-or-
Postgres + Tailwind + Webpack
Creates a new Rails project with Postgres database, Tailwind css and Webpack javascript.
rails new . -s --git --database=postgresql --css=tailwind --javascript=webpack
-or-
Postgres + Bootstrap + Rollup
Creates a new Rails project with Postgres database, Bootstrap css and Rollup javascript.
rails new . -s --git --database=postgresql --css=bootstrap --javascript=rollup
-or-
Postgres + Tailwind + Rollup
Creates a new Rails project with Postgres database, Tailwind css and Rollup javascript.
rails new . -s --git --database=postgresql --css=tailwind --javascript=rollup
After creating your Rails project, you'll need to run rails db:create
to create the local database.
Enable UUIDs
Use UUIDs as the default primary key for your models.
This template enables pgcrypto for UUIDs.
rails app:template LOCATION='https://railsbytes.com/script/V4Ys1d'
Setup authentication so that users can login to your application.
Setup Devise
Devise is flexible authentication solution for Rails with Warden.
This template adds user authentication to your app using the Devise gem.
rails app:template LOCATION="https://railsbytes.com/script/X8Bsjx"
Installation Questions:
- What do you want to call your Devise model?
User
- Do you want to any extra attributes to User?
y
- What attributes?
name
# use space separated list of attributes
Post Installation Steps:
- In
config/environments/development.rb
, addconfig.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
- Migrate Database:
rails db:migrate
Learning More:
Setup authorization so you can protect resources based on user roles.
Setup CanCanCan
CanCanCan is authorization Gem for Ruby on Rails.
This template add CanCanCan gem and generates default abilities file.
rails app:template LOCATION='https://railsbytes.com/script/V33sj3'
For more a advanced use of CanCanCan, read Lazy Load CanCanCan Abilities In Rails.
Learning More:
-or-
Setup Pundit
Pundit provides a set of helpers which guide you in leveraging regular Ruby classes and object oriented design patterns to build a simple, robust and scalable authorization system.
This template installs the Pundit gem, and runs the generator.
rails app:template LOCATION='https://railsbytes.com/script/X6ks6o'
Options for allowing ability to invite users if you're using Devise.
Setup Devise Inviteable
devise_invitable is an invitation strategy for Devise.
This template installs the gem, and runs the generator.
rails app:template LOCATION='https://railsbytes.com/script/VZgsJ0'
Allows users the ability to login to your application through other services like Google.
Setup Omniauth
Omniauth is a flexible authentication system utilizing Rack middleware.
This template adds Omniauth gem, adds OmniauthController, adds Identity model, runs migrations
rails app:template LOCATION='https://railsbytes.com/script/xkjsK3'
Post Installation Steps:
- Add or update routes in
config/routes.rb
to includeomniauth_callbacks
devise_for :users, controllers: { omniauth_callbacks: "omniauth" }
Learning More:
Add Omniauth Google Provider
omniauth-google-oauth2 is oauth2 strategy for Google.
This template adds the gem, omniauth provider, runs migration on users.
rails app:template LOCATION='https://railsbytes.com/script/V4YsP6'
Add Omniauth Github Provider
omniauth-github is oauth2 strategy for Github.
This template adds the gem, omniauth provider, runs migration on users.
rails app:template LOCATION='https://railsbytes.com/script/Vwysyy'
Add Omniauth Twitter Provider
omniauth-twitter is oauth2 strategy for Twitter.
This template adds the gem, omniauth provider, runs migration on users.
rails app:template LOCATION='https://railsbytes.com/script/XE5sQy'
Add Omniauth Facebook Provider
omniauth-facebook is oauth2 strategy for Facebook.
This template adds the gem, omniauth provider, runs migration on users.
rails app:template LOCATION='https://railsbytes.com/script/zyvsjm'
Provide soft delete functionality so you have ability to un-delete records.
Setup Paranoia
Paranoia provides soft deletes functionality to ActiveRecord.
This template installs the Paranoia gem for soft deletes.
rails app:template LOCATION='https://railsbytes.com/script/Xg8s3J'
Learning More:
-or-
Setup Discard
Discard, soft deletes for ActiveRecord done right.
This template installs the Discard gem for soft deletes.
rails app:template LOCATION='https://railsbytes.com/templates/z0gsEQ'
Learning More:
Throttle excessive requests and ban bad actors
Add Rack-Attack
rack-attack is Rack middleware for blocking and throttling requests.
This template adds the gem and default initializer.
rails app:template LOCATION='https://railsbytes.com/script/xkjs9G'
Add file upload functionality to a cloud storage services.
Setup ActiveStorage
ActiveStorage facilitates uploading files to a cloud storage service like Amazon S3, Google Cloud Storage, or Microsoft Azure.
This template adds ActiveStorage to your Rails app.
rails app:template LOCATION='https://railsbytes.com/script/zJosLx'
-or-
Setup Shrine
Shrine is a modular file upload toolkit that allows direct uploads to Amazon S3, resumable uploads, image processing and more.
This template installs Shrine gem, config initializer, plus adds some handy uploaders you can use.
rails app:template LOCATION='https://railsbytes.com/script/xYasLK'
Setup Ahoy
Ahoy is simple, powerful, first-party analytics for Rails.
This template adds Ahoy gem, runs its initializer and then migrates the database.
rails app:template LOCATION='https://railsbytes.com/script/V1bs4X'
Setup Pay
Pay add payments using Stripe or Braintree to your application.
This template adds gem and runs generators.
rails app:template LOCATION='https://railsbytes.com/script/zPdsZn'
Setup Sentry
Sentry is error tracking to performance monitoring, developers can see what actually matters, solve quicker, and learn continuously about their applications - from the frontend to the backend.
This template adds gem, initializer and application controller code.
rails app:template LOCATION='https://railsbytes.com/script/zOvsol'
-or-
Setup HoneyBadger
HoneyBadger lets you track and debug exceptions in record time.
This template adds gem, sets api key runs initializer.
rails app:template LOCATION='https://railsbytes.com/script/zNPsmV'
Bootstrap Navbar & Layout
Add Bootstrap 5 navbar and page layout, plus bunch of partials and helpers.
This template updates the layout with navbar.
rails app:template LOCATION='https://railsbytes.com/script/zmnsEn'
Bootstrap Devise Views
Add devise-bootstrap5 to get Bootstrap views for Devise.
This template adds devise-bootstrap5 gem.
rails app:template LOCATION='https://railsbytes.com/script/VeKsLE'
Bootstrap Forms
Add bootstrap_form so you can have Bootstrap forms.
This template adds bootstrap_form gem.
rails app:template LOCATION='https://railsbytes.com/script/VD7sLP'
Bootstrap Scaffold Templates
Add scaffold templates flavored for Bootstrap 5.
This template adds templates.
rails app:template LOCATION='https://railsbytes.com/script/XbBs3y'
Bootstrap Error Pages
Generate Bootstrap friendly error pages.
This template adds views.
rails app:template LOCATION='https://railsbytes.com/script/VB0sQj'
Some handy project configurations to make your life simpler.
Open Browser After Launch
This snippet will automatically open your Rails app in the browser after launch.
This template adds snippet to config.ru
.
rails app:template LOCATION="https://railsbytes.com/script/zl0s3A"
Database Migrate And Schema Dump On Heroku Deploy
Automatically migrate database and schema dump upon deploying to Heroku.
This template adds rake task.
rails app:template LOCATION="https://railsbytes.com/script/zr4spr"
Rake Task db:recreate
This rake task will drop, create, migrate and seed the database, plus clears uploads and storage.
This template adds db:recreate
rake task.
rails app:template LOCATION="https://railsbytes.com/script/VQLsoK"
Setup Bullet
Bullet helps kill N+1 queries and unused eager loading.
This template adds gem and initializer.
rails app:template LOCATION="https://railsbytes.com/script/XLEsaW"
Setup Faker
Faker is a library for generating fake data such as names, addresses, and phone numbers.
This template adds the Faker gem.
rails app:template LOCATION="https://railsbytes.com/script/Xg8sWq"
Setup Figaro
Figaro is simple Heroku-friendly configuration using ENV and a single YAML file.
This template adds Figaro for simple configuration using ENV and a single YAML file.
rails app:template LOCATION="https://railsbytes.com/script/VRZs9V"
Setup Rubocop
Rubocop is an extension focused on enforcing Rails best practices and coding conventions.
This template adds rubocop to your Rails app.
rails app:template LOCATION="https://railsbytes.com/script/XE5sl5"
Annotate Models
Annotate provides classes with schema and routes info.
This template installs gem, and runs annotations.
rails app:template LOCATION='https://railsbytes.com/script/Vqqsqg'
Setup Better Errors
Foreman is better error page for Rack apps.
This template adds Better Errors and Binding of Caller gems.
rails app:template LOCATION="https://railsbytes.com/script/V33s0D"
Improved Seeds Folder Structure
Organize your seeds files into environment folders and execute them in alphanumeric order.
This template sets up environment specific seeds folders.
rails app:template LOCATION='https://railsbytes.com/script/xGqsmL'
Access Rails Credentials Using ENV
This strategy adds a config initializer which lets you access your Rails.application.credentials
using ENV
.
This template adds a config initializer.
rails app:template LOCATION='https://railsbytes.com/script/Vp7s90'
Clear Development Logs
Automatically clear development logs when they get over 2mb.
This template adds an initializer to clear development logs.
rails app:template LOCATION='https://railsbytes.com/script/VZgs77'
GitHub Issue Templates
Creates bug reports, feature requests and code maintenance issue templates in GitHub.
This template adds some handy GitHub issue templates.
rails app:template LOCATION='https://railsbytes.com/script/XvEs4K'
GitHub Pull Request Template
Creates a pull request template for GitHub.
This template add a GitHub pull request template.
rails app:template LOCATION='https://railsbytes.com/script/VdrsPl'
Some handy git aliases I like to use to save time.
Git Add Commit Push
This alias does a git add, commit and push all on one line.
git config --global alias.add-commit-push '!git add -A && git commit -m "$1" && git push && git status'
You can use the add-commit-push
alias like this.
git add-commit-push "Add, commit, push in one line!"
Git New Branch
This alias adds, commits and pushes current changes to a new branch.
git config --global alias.new-branch '!git checkout -b "$1" && git add -A && git commit -m "$2" && git push -u origin "$1" && git status'
You can use the new-branch
alias like this.
git new-branch "123-my-branch" "Checkout, add, commit, push!"
Git New Tag
This alias creates a new tag and pushes it using the timestamp for naming.
git config --global alias.new-tag '!git tag -a -m `date +'%Y-%m-%d_%H-%M'` `date +'%Y-%m-%d_%H-%M'` && git push origin `date +'%Y-%m-%d_%H-%M'` && git status'
You can use the new-tag
alias like this.
git new-tag
Some handy extensions for Visual Studio Code.
Rails
Ruby on Rails support for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=bung87.rails
Ruby
This extension provides enhanced Ruby language and debugging support for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=rebornix.Ruby
Ruby Language Colorization
Ruby Language Colorization for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=groksrc.ruby
Ruby on Rails
This extension for Visual Studio Code adds snippets for Ruby on rails.
https://marketplace.visualstudio.com/items?itemName=hridoy.rails-snippets
Ruby Solargraph
Solargraph is a language server that provides intellisense, code completion, and inline documentation for Ruby.
https://marketplace.visualstudio.com/items?itemName=castwide.solargraph
Simple Ruby ERB
This extensions tries to provide simple Ruby and ERB support to Visual Studio Code without messing with linting or debugging.
https://marketplace.visualstudio.com/items?itemName=vortizhe.simple-ruby-erb
VSCode Ruby
This extension provides improved syntax highlighting, language configuration, and snippets to Ruby and ERB files within Visual Studio Code.
https://marketplace.visualstudio.com/items?itemName=wingrunr21.vscode-ruby
Ruby Rubocop
This extension provides interfaces to rubocop for vscode.
https://marketplace.visualstudio.com/items?itemName=misogi.ruby-rubocop
Visit railsbytes.com for other handy templates to help setup your project.
If you are looking for Rails tutorials, I'd highly recommend you checkout gorails.com and driftingruby.com, both great resources for learning Rails.