Smoothing Rails development in Bash

This post covers a few ways that I’ve automated the repetitive tasks that are required while building and deploying Rails apps.

Rails console

In Rails 2 apps, you get a console by running ./script/console, but in Rails 3, you get a console by running ./script/rails console. Because I want to open a console without having to remember which version of Rails I’m using, I wrote an alias to figure it out and do the right thing for me.

SSH Host Keys

Deploying apps to EC2 or something similar means that you will inevitably run into SSH telling you that the host key has changed and you could be experiencing a man-in-the-middle attack. Making the error go away requires opening your known_hosts file, finding the right line, deleting it, saving the file, and then trying again. It’s a giant pain in the ass.

The most common “fix” that I have seen is to disable host key checking entirely, but that removes the security provided by host keys. My fix is to be able to remove stale host keys quickly and then get back to what I was doing.

Running specs

Similar to the console, running specs in Rails 3 apps requires RSpec 2 and the rspec binary. Specs in Rails 2 require RSpec 1 and the spec binary. Fortunately, the spec_helper.rb helps us distinguish between versions of RSpec, so we can just run the tests without stressing about versions.