Using Passenger for development (with optional SSL)
Run a Rails app locally with Apache and Passenger for development, including optional HTTPS using a self-signed certificate.
Revive a shell that is not working any more
A frozen or garbled shell often recovers with Ctrl-Q after accidental Ctrl-S, or with reset when terminal output settings are corrupted.
Convert Haml to ERB
Haml markup can be migrated to ERB with haml2erb, but the conversion is only partly automated and still needs manual cleanup.
Basic styles for flash notifications
.notice,
.error,
.information,
.warning {
font-weight: bold;
}
.notice {
color: #11bb00;
}
.error {
color: #F53A31;
}
.information {
color: #557;
}
.warning {
color: #d07d2d;
}
Start delayed_job in the background
This starts delayed_job, hiding all the output and hiding the process in the background.
rake jobs:work &>/dev/null &
How to install the date_performance gem
sudo gem install zip
git clone git://github.com/rtomayko/date-performance.git
cd date-performance
rake package:build
cd dist
sudo gem install --no-ri --no-rdoc date-performance-0.4.7.gem
Clear a Solr index with acts_as_solr
ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "#{Location.solr_configuration[:type_field]}:#{ModelClass}"))
ActsAsSolr::Post.execute(Solr::Request::Commit.new)
Starting and stopping Solr
Solr listens to different ports for different environments.
Start Solr (and hide useless output)
rake solr:start PORT=8981 &>/dev/null
rake solr:start PORT=8982 &>/dev/null
Stop Solr
rake solr:stop PORT=8981
rake solr:stop PORT=8982
Run a single Cucumber feature
Run one Cucumber feature file directly with script/cucumber, or invoke it through rake when speed is less important.
Install a gem without RI and RDdoc
Speed up gem installs by skipping RI and RDoc generation with gem install --no-document; a global ~/.gemrc setting can disable local documentation support.
Calling class methods
To call a class method (or static method) from an instance method:
class.method()
To call a class method from a class method:
method()
Fixing "A copy of Klass has been removed from the module tree but is still active"
Development error from mixing non-reloading code with autoloaded classes, often after a stale class reference or cached instance keeps an unloaded constant alive.
Create an application with an older Rails version
sudo gem install rails --version="=1.2.3"
rails _1.2.3_ new-project-folder
Freeze a specific Rails version
sudo apt-get install unzip
rake rails:freeze:edge RELEASE=2.2.2
Show the current Git branch on your Bash prompt
Display the active Git branch directly in the Bash prompt by customizing PS1, so the current repository state is visible while working in the shell.
Run a single test in Test::Unit
Run one Test::Unit file, method, or name-matching subset directly from the command line when a full test suite is unnecessary.
Typical .gitignore
Common ignore list for source control that keeps logs, temporary files, local databases, IDE settings, and generated assets out of git history.
Check out a remote branch in git
Check out a remote branch locally and set up tracking so future pulls and pushes stay linked to origin.
Git for Subversion users
Quick Git commands for former Subversion users who need to clone, stage, commit, push, pull, branch, stash, and restore files.
Use the ALT key in a VirtualBox Windows VM
ALT input in a VirtualBox Windows VM can feel locked on Ubuntu. Workarounds let the Windows key act as ALT or change key mapping.
Order of the state_machine callback chain
Callback order in state_machine matters when transitions depend on validation and persistence; aborting the chain can stop a transition from completing.
How to fix "Too many authentic authentication failures" with SSH and/or Capistrano
SSH or Capistrano connections can fail when ssh-agent offers too many keys and servers stop after repeated authentication attempts.