Cross-email-client compatible background image helper

If you've ever dealt with HTML email before, you know that it's a really big pain in the behind. Email clients differ widely in their HTML and CSS support, so it's almost impossible to create compatible HTML layouts without the use of tables and other archaic front-end techniques.

One of the most fundamental things you may want to do in an HTML email is add a background image to some element. While this task is easy in most web browsers, it's not so with email clients. I stumbled across an article on Campaign Monitor that outlined a method for adding background images that is compatible with many (still not all) modern email clients.

Needing to use this method fairly often, I thought I'd turn it into a Rails view helper. This is what I came up with:

It's not perfect, but it does the trick for me.