May 13

Rails tip: Log which line called redirect_to

Here’s a quick Rails tip that has come in handy recently.

The Setup

Occasionally I need to trace a bug through the server logs. A user might have some completely un-reproducible error, or I might be trying to get a better idea of where to look for some vague problem. Often times this boils down to an unexpected redirect

Mar 27

Using New Relic in a Rack app

I recently switched this blog from a full-on Rails 3 app to Toto, which is a Rack based blog app implemented in fewer than 300 lines of Ruby. I had New Relic enabled in my Rails 3 blog, so I figured it would be pretty easy to integrate it with a Rack app too. Just flip a switch, right? Well, not quite - in this post, I’ll go through the process of adding detailed New Relic instrumentation to a Rack app.

Mar 18

Placing geo-coordinates on an image


One recent project I’ve been working on involves dropping pins on a map of the world at locations that correspond to Google geolocation (longitude/latitude) coordinates. This seemed like a simple problem that I could find a thousand and one tutorials for, but turned out to be rather tricky - and I never did find a clear explanation of the process anywhere. So here’s a (hopefully) straightforward method for converting Google geo coordinates to pixel locations on a map image.

Mar 11

Implementing a Rails 3 View Resolver

One of the biggest tasks in our recent upgrade from Rails 2.2.2 to Rails 3.0.45 at Bonanza was the re-implementation of all of our Rails monkey patches custom initializers to work with Rails 3. This upgrade presented a pleasant pattern (which we happily took as further validation of our move to Rails 3) of taking large, fragile patches and re-implementing them as significantly smaller chunks of code - in many cases using public APIs now exposed by Rails.

In the case that spurred this post, we have some functionality implemented by subclassing some of our main controllers and overriding a small subset of their methods. To alleviate the need to replicate view templates between the parent and child controllers, we extended view template lookup to walk up the controller inheritance tree (up to ActionController::Base) until a particular view template could be found.