I spent a bunch of time the last couple of days sprucing up a few of my personal projects. Today was mostly spent on the lunchomizer, which gives you random suggestions for lunch, based on your location. It still only works for Midtown Manhattan since the locations all come from Midtown Lunch and that’s also the neighborhood where I happen to work.
The biggest change today was fixing the HTML5 location support and a much better mobile experience via a separate Rails layout tailored for small screens. All in all, it was pretty easy, but one thing that surprised me was a noticeable lack of a de facto standard library for doing mobile, or really any, browser detection. I ended up using a gem called Nomadic and that worked well with the following controller code:
class LunchController < ApplicationController layout :choose_layout [...] private # use mobile layout for mobile clients (using browser detection) def choose_layout Nomadic.mobile?(request.env) ? "mobile" : "default" end end
A fairly simplistic solution, but perfect for this app which has only a single controller and a single view :)
And for the curious, the full source is available on github. Fork away!