Mobile Rails applications, part 1: An overview
August 22, 2010
The Mobile Fu plugin for Rails is an easy way to quickly get a mobile version of your application up and running. Mobile Fu detects if a user is coming from a mobile device, and if so, returns a mobile-friendly view and CSS instead of standard ones. You just need to add a line to your
application_controller.rb file, add the
:iphone MIME type, and create mobile-specific views. Mobile Fu will also render any platform-specific CSS you create. This means you can use separate CSS depending on whether your app is being viewed on an iPhone, iPad, Blackberry, etc.—very useful, potentially. This is the method I used to create a basic mobile version of a data collection tool at my day job, allowing school administrators to observe classrooms and record what they see using their phones. How to get this started is all lined out well in the plugin’s README.
In lieu of any other drop-in solutions, the next best route may be to roll your own mobile-enabling code. As it turns out, it’s not that hard—a Railscasts episode on mobile websites covers the requirements, using largely the same approach as Mobile Fu, but adds some additional functionality that Mobile Fu doesn’t explicitly provide. In particular, Ryan Bates shows how to allow users to switch between the mobile version and the standard version. It also looks like it will be easier to augment with my own code, such as:
- Mobile detection: Ryan’s regular expression might be worth revisiting. It may be possible to borrow from Mobile Fu’s detection to make this more thorough, and hopefully return more specific device types.
- Check for iPads and tablets: I see this becoming more important moving forward. Depending on the app, I may not even want to bother with a mobile version when rendering for a tablet’s larger screen.
If these aren’t issues for you, and you just want to create a mobile site that will work on Webkit-based devices, watch the Railscasts episode and you’re well on your way.
My next steps, which I plan to document here in the coming days, are to refine some of my understanding of jQTouch with Rails (specifically form handling) and figure out what styles are missing from the default jQTouch templates (I’m using the Apple theme instead of the jQT theme; its brighter look will appeal more to my audience). From there I want to get into a more advanced mobile browser check to determine which version of my mobile site to send to a given device. To be continued, but if you have questions or suggestions in the meantime please share them.
blog comments powered by
Rails testing made simple
Learn to test Rails apps the way
I learned, building up tests step-by-step, in
Everyday Rails Testing
Expanded to include exclusive content and a complete sample Rails application.
Learn more »