We’ve been finished with Chow for about a month now, and that’s cool. (PJ wrote about the launch back in the day.) The site is stable and it’s our second from-scratch Rails site at CNET, the first being Chowhound. Party time, right? Right.
Since it seems like we did something correct, I’d like to share with you our toolbox. We have no golden hammer, but we sure use some kickass open source software. This is just a high level overview, but who knows? Maybe a hammer or tape measure you find within will be new and useful to you. I can only hope.

Servers
The muscle, scar tissue, and bone running our site are nothing unusual. Rails convention: a hardware load balancer to Apache 2.0 to Pen to a cluster of Mongrels. Coda Hale has an infamous tutorial on setting up a similar architecture and Zed maintains a stellar documentation page over at the Mongrel site. We have had very few problems with Mongrel and Pen is so quiet that I often forget it exists.
Behind the backend we run an installation of Solr as our search engine. It’s Java, but a nice XML-RPC API helps alleviate the pain. A dedicated wiki page is available with Ruby help (which you probably won’t need). A cron or two is needed to insert items into the index, mind you.
We (of course) run memcached and use it to cache tons of data. This helps keep our site speedy and takes the load off our largeish database. In case you missed it, a previous Err post touches on memcached. It’s a lot easier to use than you might think.
Finally, we use MySQL for our database. Big surprise there.
Deployment
Like any red blooded America, we use Capistrano for deployment. There’s really no other option. The mailing list is invaluable, as are the various tidbits scattered across the internet. There’s even a great cheat sheet.
We also use monit to handle our production environment. monit is a nice program which provides a web interface for monitoring your apps. It will restart troubled processes and e-mail you when trouble arises. On top of that, it can also watch to make sure daemons don’t take up too much CPU or memory and kill them when they do. It uses a nice little DSL for its config files and, as long as you have a pid file, is easy to get up and running with. There’s a nice starter monit config file here and plenty of resources out there. monit can even replace mongrel cluster. Highly recommended.
Plugins
Okay, we use a lot of plugins. I’m going to make this a bullet list. Just pretend it’s a PowerPoint presentation and it should seem more familiar. Er, on second though, don’t.
acts_as_cached
Already mentioned further up, we use memcached to cache many database queries. This plugin supports model caching, session caching, and fragment caching out of the box. A simply memcached.yml is added to our config/ directory and we can forget about it. The README file provides a wealth of common idioms and a mailing list keeps patches (and bug reports) flowing. Essential.
query_trace
Completely essential. This plugin attaches a short backtrace to every SQL query in your log files. The first time I heard this I thought, ‘so what?’ Well it’s a big deal. Suddenly you know exactly what is going on with your ActiveRecord code—you know the exact line number from which queries are being spawned. When you’re trying to cache everything using memcached, this goes a huge way in helping you lock down your database.
exception_notification
Again, essential. E-mails us whenever an exception is raised on the site. Some days I just gather up the exceptions in my Inbox and bang away on those bugs for an hour or two. No more e-mails. It’s very gratifying. Best part is, you can control whether certain exceptions show a 500 or a 404, and you can even set the prefix of the e-mails you receive. For instance, I can set the e-mail prefixes then setup mailbox filters to have all the e-mails prefixed with [CHOW] go to my Inbox and all the e-mails prefixed with [CHOWHOUND] go into my trash can. Very slick.
acts_as_textiled
The first ‘official’ plugin extracted from our work, acts_as_textiled lets us forget about rendering Textile. Instead of having to ask ‘should I render Textile?’, the question becomes ‘should I not render Textile?’ If a story description uses Textile, we always want it rendered—except in special circumstances. It’s nice to not have to use the textile helper all over our app and instead focus on things that matter. Like pastels.
acts_as_solr
This is a bit of a white lie. We’re currently using a plugin PJ rolled called ‘acts_as_indexed,’ but he is in the process of transferring our stuffs over to acts_as_solr. It’s a fine piece of work and written by people who know Lucence (and solr) inside and out. One of those dudes even wrote a book, I hear.
debug_view_helpers
This is a real life saver. If you’ve ever used Smarty, you know how great that ‘debug’ window is that pops up. There’s no ambiguity for your CSS people: all the available variables are shown right there in a pop-up window. We installed this plugin and set the ‘debug’ link to appear a) in development mode b) if you’re on the VPN. That means, even in production mode, authorized elite personnel can always see the variables available to the view. So awesome for debugging. (Plus it means I don’t have to talk to our CSS guy, Todd, so much. He is weird.)
has_many_polymorphs
Evan Weaver’s crazy plugin lets us forget about all the black magic we learned from Josh Susser. Little o’ this:
class Tag < ActiveRecord::Base has_many_polymorphs :tagged_things, :from => [:posts, :files, :tags] end
Yup. Very nice. Also lets you do Tag.find(:all, :include => :tagged_things) and fetches the result in one query. That is, if you’re using MySQL or Postgres.
request_routing
Hey, check out this code:
map.connect '', :controller => 'mobile', :conditions => { :subdomain => 'm' }
Can you believe that’s not in core? It’s so great, and thanks to the request_routing plugin we’re able to use it for Chow’s mobile site. Plus, Dan Webb’s blog is hot. There. I said it.
redbox
You just have to see it for yourself. Real nice code which lets you pull off that whole ‘lightbox dialog’ thing. We’re using it for the ‘E-mail to a Friend’ links. Nice.
unicode_hacks
Right now, Unicode seems to fall down when you need to pattern match against it or do any sort of manipulation. Lucky for us we just do input and output. Until the new Rails hits the streets, we rely on the unicode_hacks plugin to get those crazy characters in and out of our database correctly.
browser_filters
Safari crashing randomly? We (correctly) suspected Unicode. This Super Official Rails Plugin solved our problems and may solve yours. Also provides a few more fixes and tweaks.
composite_migrations
Yes, we’re crazy enough to use composite primary keys. That’s just the way some of us were raised. This home rolled plugin allows us to create the dastardly fellows in a migration so that we may use the composite primary key gem freely and openly in our code. Hey, we’ve got opinions, too.
Libraries
First and foremost, hpricot is an amazing invention and a huge help. Scraping and parsing HTML/XML isn’t something we think twice about anymore. We use hpricot on more than XML import feed because it’s just so damn easy. If you’ve never given it a shot, I recommend trying it soon.
Both Dr Nic’s Magic Models and Camping are used by us to prototype all sorts of ideas and internal tools. Some of our top secret monitoring tools run using a combination of the two. Being fluent in Camping, and knowing some tricks to get it working with Magic Models, is a must.
RFuzz, available as a standard Ruby gem, is a library which makes it trivial to test web sites. We run periodic RFuzz tests against our live sites to make sure they’re alive, bullet proof, and speedy. The tests run just like unit tests and help us feel that much better about our babies. During the big security fiasco RFuzz was instrumental, and since I’ve fallen in love.
When it comes to testing, nothing gives me more pleasure than color. Thanks to Pat Eyler, the redgreen gem makes all those little repetitive dots that much more bearable.
Use autotest. It takes your mind off the testing and lets you focus on the tests.
FasterCSV is a gem you can get from the standard repository. One of our data feeds is delivered as Excel, which is basically completely useless. So we export it to CSV then import it with FasterCSV, which can nail about 5000 records in 2 seconds. Awesome.
Mocha is a library for stubbing and mocking tests. Because of it, I’ve slowly been moving over to a fixture-less state of mind. There’s all sorts of information out there on using Mocha, so dive right in.
First made known to me by technoweenie, Piston is an incredible tool for managing Rails plugins. We had troubles when deploying with svn:externals set: our server would try to make too many connections to the external SVN server too quickly. As a result, the connections would die and the deploy would fail. Piston solved this issue: we can keep plugins in our local repository and sync them up with their remote repository whenever we want. So far it’s been working out wonderfully, and so easy! If you haven’t started yet, get on the Piston bandwagon immediately.
Editing
Sorry, I admit it: I’m not a TextMate guy. Sure, I’m writing this post in TextMate, but I still prefer vim for coding. I know there’s at least one duder out there who can side with me. For that one guy (you know who you are), here’s a few classy vim links: the wiki page, the gem, the Rails plugin, and the html-macros plugin. All essential.
Outliers
Like everyone else, we use Subversion and Trac to manage our source code and tickets. We also use Marshmallow and a polling Ruby process to notify us of changes to Subversion. It’s helpful to see the commits in Campfire because they’re always there, whether you are or not.
We recently started using Crazy Egg to check out clicks on our site and wow wow wow. Everyone has already talked about it, but I suggest trying it out. So easy, and it gives you an entirely new perspective on your site.
Hammers and Tape
So that’s my toolbox. Maybe I missed a few screws or rulers, sure, but you get the general idea. Have any really great levels you want to share? Hit me in the comments.