I use this Capistrano recipe at work to send a broadcast to the office when I deploy an update. We use Jabber, and have a broadcast user that forwards messages to every user.

Copy jabber.yml to config/jabber.yml. Edit the details in it:

username: The Jabber account that will be **SENDING** alerts
          to the broadcast account

password: The password for the above Jabber account

broadcast: The Jabber broadcast account configured to forward
           messages to all users

Drop jabber.rb to config/deploy/jabber.rb. Add load "config/deploy/jabber.rb" to config/deploy.rb.

When you deploy and Capistrano hits the web:disable and web:enable tasks, a message will be sent to your users indicating the system is down. You can customize this message like so:

JABBER_REASON='a database migration' JABBER_DOWNTIME='10 minutes' cap deploy
JABBER_REASON='everything is broken' JABBER_DOWNTIME='a long time' cap deploy:web:disable

I extracted a few pieces of code into Rails Plugins.

  • Cars: Helpers for populating dropdowns with automobile makes and models
  • Host Router: Allows creation of routes based on hostname or port
  • Multisite: Provides site-specific view paths
  • Remote Database: Helpers for working with databases on multiple hosts
  • Fraud Guardian: Helpers for generating fraud reports via FraudGuardian

Nothing spectacular, but maybe they’ll help someone else.

I needed HTTP basic authentication for a Sinatra app running as a Rails Metal. I have two apps, one running Clearance and another running Authlogic.

Using the info from my previous post, I wrote a small Sinatra plugin that works with both Clearance and Authlogic.

Throw the file above in lib/sinatra_authentication.rb. Then, your metal, app/metals/api.rb would look something like this:

Authlogic doesn’t have an authenticate method, so I added this to app/models/user.rb:

Hope it helps someone else.

Recently, I needed to write an API to work with an iPhone application. I used Clearance for authentication. Unfortunately, it doesn’t support HTTP Basic Authentication out of the box, which made it difficult to use in an API.

I found this issue with a patch that worked. However, the Thoughtbot guys said that Rack::Auth::Basic should be used instead. No examples were provided.

I tried for a few days to get things to work with Rack and ended up using that patch.

Today I decided to take another look at this. I found a cached slideshow on Google that had the info I needed to make an API using a Sinatra app as a Rails Metal.

This is basically how I got HTTP Basic Auth working with Clearance:

Hope it helps someone else having this problem.

I missed Ruby’s Array.first and Array.last methods coding in Javascript tonight, so I wrote them myself: