SlideShare uma empresa Scribd logo
1 de 24
Baixar para ler offline
Rails Cantrips
We make modern web
applications for desktop, mobile,
and augmented reality.
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

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

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

Semelhante a Rails cantrips

Semelhante a Rails cantrips (20)

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

Último

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 

Último (20)

WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 

Rails cantrips

  • 2.
  • 3. We make modern web applications for desktop, mobile, and augmented reality.
  • 4.
  • 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