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:
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.
Update: part two of this series is now available.
I stand with the Black community against systemic racism, police violence and brutality, intolerance, and hate in the United States and worldwide. We must all demand better from our leaders, and ourselves. Stop tolerating intolerance.
While you're here, please consider making a donation to Black Girls CODE, who do great, important work to provide opportunity to underprivileged girls interested in tech, or any organization working toward equity and safety for all, not just the privileged. Thank you.
If you liked my series on practical advice for adding reliable tests to your Rails apps, check out the expanded ebook version. Lots of additional, exclusive content and a complete sample Rails application.
Ruby on Rails news and tips, and other ideas and surprises from Aaron at Everyday Rails. Delivered to your inbox on no particular set schedule.