SlideShare a Scribd company logo
Rails Cantrips
Rails cantrips
We make modern web
applications for desktop, mobile,
and augmented reality.
Rails cantrips
Environment
Have open files in a different editor,
and use to make it nice.
better_errors Eg.
# Gemfile
gem 'better_errors', group: :development
# config/environments/development.rb
BetterErrors.editor = :sublime
subl_handler
Disable generation of gem docs for fast gem installs:
# ~/.gemrc or /etc/gemrc
gem: --no-rdoc --no-ri
Multiplex ssh for faster connections
# ~/.ssh/config
Host *
ControlMaster auto
ControlPath ~/.ssh/master-%C
A .railsrc file for default database
# ~/.railsrc
-d postgresql
for autocomplete and syntax highlightingpgcli
# ln -s /usr/local/bin/pgcli ./bin/psql
rails db
Configuration
Put your reusable code in extras, and make it eager
loaded on production:
Don't put it somewhere under lib. For more info see
this .
# config/application.rb
config.paths.add 'extras', eager_load: true
Arkency post
Organize your locale files:
So you can have folders for mailers, models, views, etc.
# From this default:
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}'
# to using a recursive directory glob:
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,
Ensure the session cookie is only served over https,
with secure flag.
Rails.application.config.session_store :cookie_store,
key: '_app_session', secure: !Rails.env.development?
Move database.yml to database.yml.sample, remove
the production stanza. Add database.yml to
.gitignore, then update bin/setup:
# uncomment these lines in bin/setup
puts "n== Copying sample files =="
unless File.exist?('config/database.yml')
cp 'config/database.yml.sample', 'config/database.yml'
end
Getting errors in sidekiq from other projects?
Configure redis to use a different database for each
project via a REDIS_URL env variable
Managed easily using .
# .env
REDIS_URL=redis://127.0.0.1:6379/2
dotenv
Gems
Handy way to obfuscate mailto links from spambots:
# Gemfile
gem 'actionview-encoded_mail_to'
# in a template
<%= mail_to "weston@netsign.com", "Email me", encode: "javascript" %>
Use bundler's open command:
Can customize which editor with BUNDLER_EDITOR
bundle open devise
Boilerplate
Migrations getting unwieldly? Have legacy data
transforms? Collapse your migrations.
Delete all your other migrations, rake
db:migrate:reset
class CollapseMigrations < ActiveRecord::Migration
def up
# schema.rb's ActiveRecord::Schema.define() block
end
def down
raise ActiveRecord::IrreversibleMigration
end
end
WrappingForm for contextual validations ...
# hat tip to Max Savchenko @robotector
class WrappingForm
include ActiveModel::Model
def initialize(model)
@model = model
end
attr_reader :model
end
class UpdateProfileForm < WrappingForm
delegate :first_name, :last_name, to: :model
validates :first_name, :last_name, presence: true
end
Use capistrano for remote tasks:
namespace :remote do
desc 'Run a remote rake task, example: "cap staging remote:rake[db:version]"'
task :rake, [:task] do |t, args|
on primary fetch(:migration_role) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :rake, args.task
end
end
end
end
desc 'Run a remote command, example: "cap production remote:cmd[ps,aux]"'
task :cmd, [:cmd, :options] do |t,args|
on primary fetch(:migration_role) do
Thank you
Weston Triemstra
@thermistor
weston@netsign.com

More Related Content

PPTX
Cyansible
PPTX
Automating aws infrastructure and code deployments using Ansible @WebEngage
PDF
CI/CD with Kubernetes, Helm & Wercker (#madScalability)
PDF
Ansible 2 and Ansible Galaxy 2
PDF
VSTS Release Pipelines with Kubernetes
PDF
Testing with Ansible
PDF
Phoenix for Rails Devs
PDF
Ansible Introduction
Cyansible
Automating aws infrastructure and code deployments using Ansible @WebEngage
CI/CD with Kubernetes, Helm & Wercker (#madScalability)
Ansible 2 and Ansible Galaxy 2
VSTS Release Pipelines with Kubernetes
Testing with Ansible
Phoenix for Rails Devs
Ansible Introduction

What's hot (20)

ODP
Using Ansible at Scale to Manage a Public Cloud
PDF
Architecting for the cloud
PPTX
Ansible presentation
PDF
Getting Started with Ansible
PPTX
DotNet Conf Valencia 2019 - Building cloud native apps with .NRT core 3.0 and...
PDF
Ansible introduction - XX Betabeers Galicia
PDF
DevOps
PDF
Ansible, best practices
PDF
DevOps - Infrastructure as Code by Andre Marcelo-Tanner
PPTX
Dev ops meetup
PDF
Ansible Intro - June 2015 / Ansible Barcelona User Group
PDF
Scripting Embulk Plugins
PDF
Ansible with AWS
PDF
Infrastructure = Code
PDF
A quick intro to Ansible
PPTX
9 ways to consume kubernetes on open stack in 15 mins (k8s meetup)
PDF
DevOps in a Regulated World - aka 'Ansible, AWS, and Jenkins'
PDF
What's New in v2 - AnsibleFest London 2015
PDF
Introduction to ansible galaxy
PPT
Capistrano
Using Ansible at Scale to Manage a Public Cloud
Architecting for the cloud
Ansible presentation
Getting Started with Ansible
DotNet Conf Valencia 2019 - Building cloud native apps with .NRT core 3.0 and...
Ansible introduction - XX Betabeers Galicia
DevOps
Ansible, best practices
DevOps - Infrastructure as Code by Andre Marcelo-Tanner
Dev ops meetup
Ansible Intro - June 2015 / Ansible Barcelona User Group
Scripting Embulk Plugins
Ansible with AWS
Infrastructure = Code
A quick intro to Ansible
9 ways to consume kubernetes on open stack in 15 mins (k8s meetup)
DevOps in a Regulated World - aka 'Ansible, AWS, and Jenkins'
What's New in v2 - AnsibleFest London 2015
Introduction to ansible galaxy
Capistrano
Ad

Similar to Rails cantrips (20)

PPTX
Rails Engine | Modular application
PPTX
Ruby on Rails and Docker - Why should I care?
PPTX
Deploying your web application with AWS ElasticBeanstalk
PDF
Deploying a simple Rails application with AWS Elastic Beanstalk
KEY
Rails web api 开发
PDF
DCEU 18: Developing with Docker Containers
PDF
Hands on Docker - Launch your own LEMP or LAMP stack - SunshinePHP
PPT
Containers 101
PDF
Practical Chef and Capistrano for Your Rails App
PDF
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
PPTX
Kubered -Recipes for C2 Operations on Kubernetes
PPTX
Docker for Web Developers: A Sneak Peek
PDF
Deploying configurable frontend web application containers
PDF
Chef - industrialize and automate your infrastructure
PDF
Infrastructureascode slideshare-160331143725
PPTX
Infrastructure as code: running microservices on AWS using Docker, Terraform,...
PDF
Infrastructureascode slideshare-160331143725
PDF
Docker for developers on mac and windows
ODP
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
PDF
Kubernetes - training micro-dragons without getting burnt
Rails Engine | Modular application
Ruby on Rails and Docker - Why should I care?
Deploying your web application with AWS ElasticBeanstalk
Deploying a simple Rails application with AWS Elastic Beanstalk
Rails web api 开发
DCEU 18: Developing with Docker Containers
Hands on Docker - Launch your own LEMP or LAMP stack - SunshinePHP
Containers 101
Practical Chef and Capistrano for Your Rails App
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
Kubered -Recipes for C2 Operations on Kubernetes
Docker for Web Developers: A Sneak Peek
Deploying configurable frontend web application containers
Chef - industrialize and automate your infrastructure
Infrastructureascode slideshare-160331143725
Infrastructure as code: running microservices on AWS using Docker, Terraform,...
Infrastructureascode slideshare-160331143725
Docker for developers on mac and windows
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
Kubernetes - training micro-dragons without getting burnt
Ad

Recently uploaded (20)

PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
iTop VPN Free 5.6.0.5262 Crack latest version 2025
PDF
Complete Guide to Website Development in Malaysia for SMEs
PDF
Tally Prime Crack Download New Version 5.1 [2025] (License Key Free
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
medical staffing services at VALiNTRY
PPTX
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
PDF
AutoCAD Professional Crack 2025 With License Key
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Salesforce Agentforce AI Implementation.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
CHAPTER 2 - PM Management and IT Context
Why Generative AI is the Future of Content, Code & Creativity?
Internet Downloader Manager (IDM) Crack 6.42 Build 41
iTop VPN Free 5.6.0.5262 Crack latest version 2025
Complete Guide to Website Development in Malaysia for SMEs
Tally Prime Crack Download New Version 5.1 [2025] (License Key Free
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
medical staffing services at VALiNTRY
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
AutoCAD Professional Crack 2025 With License Key
Operating system designcfffgfgggggggvggggggggg
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
Design an Analysis of Algorithms II-SECS-1021-03
Salesforce Agentforce AI Implementation.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Navsoft: AI-Powered Business Solutions & Custom Software Development
Wondershare Filmora 15 Crack With Activation Key [2025
wealthsignaloriginal-com-DS-text-... (1).pdf
CHAPTER 2 - PM Management and IT Context

Rails cantrips

  • 3. We make modern web applications for desktop, mobile, and augmented reality.
  • 6. Have open files in a different editor, and use to make it nice. better_errors Eg. # Gemfile gem 'better_errors', group: :development # config/environments/development.rb BetterErrors.editor = :sublime subl_handler
  • 7. Disable generation of gem docs for fast gem installs: # ~/.gemrc or /etc/gemrc gem: --no-rdoc --no-ri
  • 8. Multiplex ssh for faster connections # ~/.ssh/config Host * ControlMaster auto ControlPath ~/.ssh/master-%C
  • 9. A .railsrc file for default database # ~/.railsrc -d postgresql
  • 10. for autocomplete and syntax highlightingpgcli # ln -s /usr/local/bin/pgcli ./bin/psql rails db
  • 12. Put your reusable code in extras, and make it eager loaded on production: Don't put it somewhere under lib. For more info see this . # config/application.rb config.paths.add 'extras', eager_load: true Arkency post
  • 13. Organize your locale files: So you can have folders for mailers, models, views, etc. # From this default: config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}' # to using a recursive directory glob: config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,
  • 14. Ensure the session cookie is only served over https, with secure flag. Rails.application.config.session_store :cookie_store, key: '_app_session', secure: !Rails.env.development?
  • 15. Move database.yml to database.yml.sample, remove the production stanza. Add database.yml to .gitignore, then update bin/setup: # uncomment these lines in bin/setup puts "n== Copying sample files ==" unless File.exist?('config/database.yml') cp 'config/database.yml.sample', 'config/database.yml' end
  • 16. Getting errors in sidekiq from other projects? Configure redis to use a different database for each project via a REDIS_URL env variable Managed easily using . # .env REDIS_URL=redis://127.0.0.1:6379/2 dotenv
  • 17. Gems
  • 18. Handy way to obfuscate mailto links from spambots: # Gemfile gem 'actionview-encoded_mail_to' # in a template <%= mail_to "weston@netsign.com", "Email me", encode: "javascript" %>
  • 19. Use bundler's open command: Can customize which editor with BUNDLER_EDITOR bundle open devise
  • 21. Migrations getting unwieldly? Have legacy data transforms? Collapse your migrations. Delete all your other migrations, rake db:migrate:reset class CollapseMigrations < ActiveRecord::Migration def up # schema.rb's ActiveRecord::Schema.define() block end def down raise ActiveRecord::IrreversibleMigration end end
  • 22. WrappingForm for contextual validations ... # hat tip to Max Savchenko @robotector class WrappingForm include ActiveModel::Model def initialize(model) @model = model end attr_reader :model end class UpdateProfileForm < WrappingForm delegate :first_name, :last_name, to: :model validates :first_name, :last_name, presence: true end
  • 23. Use capistrano for remote tasks: namespace :remote do desc 'Run a remote rake task, example: "cap staging remote:rake[db:version]"' task :rake, [:task] do |t, args| on primary fetch(:migration_role) do within release_path do with rails_env: fetch(:rails_env) do execute :rake, args.task end end end end desc 'Run a remote command, example: "cap production remote:cmd[ps,aux]"' task :cmd, [:cmd, :options] do |t,args| on primary fetch(:migration_role) do