Capitalizing Apple Products in Ruby (and more)

I've been doing a bit more Ruby and Ruby on Rails coding lately by virtue of silently commandeering the codebase. shhhh, it can be our secret.

Riding the Pipeline of Assets

Last month I upgraded the site from Rails 2.3 to Rails 3.1; getting up and running on the asset pipeline was a much larger project than I imagined, and while I had plans for a supremely awesome post on all the details of the upgrade, I spent less time taking notes on all the cute little steps and more time… LOST IN TIME AND SPACE with all the…. complications. #ahem

This week I got the site running on Rails 3.2, which thankfully was pretty easy. The instructions on were succinct and helpful. I did run into a few minor hiccups but overall it was a breeze. The biggest problem I ran into was one involving Rack 1.4.1 and cookies. For a view of the crime scene, check the gist.

A quick search on StackOverflow told me a lot of others were having this issue as well, but a simple act of clearing cookies fixed their problem. It wasn't so easy in my case. In the end I had to rollback to Rack 1.4.0, but I've got my fingers crossed for a fix in some future release.

i to the P

With Rails upgrades out of the way, I am focusing on smaller enhancements here and there as time permits. This week I added a helper file for our blog categories. These categories are generated dynamically based on the popularity/density of tags in blog posts (thanks to Michael Bleigh's Acts As Taggable On gem), but I wanted to capitalize the category names and appropriately not capitalize the "i" in words like "iPhone" and "iPad" and consequently capitalize the second letter in those specific words. It's not rocket science, but if you are upper-casing words in your app and want to create exceptions for Apple products, here's some code for you:

module TagHelper   def tag_title(tag)     name =     iProduct = %w(iphone ipad)     if iProduct.include?(name)       apple_product_titlize(name)     else       name.capitalize     end   end    def apple_product_titlize(name)     name[0] + name[1].capitalize + name[2..-1]   end end 

This method is called by a bit of Ruby in our view:

<% @categories.each do |tag| %>   <li><%= link_to "#{tag_title(tag)} (#{tag.count})", "/tag/#{}" %></li> <% end %> 

The Before & After

Updates? Yeah, we do that

So there you have it – a long overdue update on upgrades and a snippet of code to help you manage the "i" pandemic.

Happy coding!