I started wondering a few days ago, "Why don't we have an iPhone version of the Plexus site?" So I did some research and found that enabling a Ruby on Rails site for the iPhone was easier than I thought. I found a great tutorial outlining how to create a custom mime-type and create iPhone-specific pages.
I took advantage of a few tools to make my job a bit easier. iUI is a collection of javascript and css files that enable ajax, sliding page loads, and presentation to more closely resemble a native iPhone application. iPhoney is a Mac desktop application that emulates what your site might look like on a real iPhone.
But, with all the best laid plans, a few snags arose.
Plexus takes advantage of page caching to speed up load times. This presented a problem because I didn't want to cache the iPhone views, only the HTML views. The caches_page method in Rails will take a hash with a Proc to prevent pages from being cached under certain conditions. This is the example they give in the documentation:
The application will not cache any action that is being requested in json format. This approach didn't quite work because I created a custom mime type called iphone. After some hacking and failing, I finally came up with the following solution for not caching pages for the iPhone:
Definitely not the prettiest way to detect the iPhone format, but the only one I found that would work reliably. It checks the HTTP_USER_AGENT for Mobile Safari (that way, you can catch the iPhone and the iPod Touch).
Another problem I ran into was trying to keep the iPhone from loading the cached HTML views. This problem was a lot easier to fix. I just had to add the following RewriteRules to the site's conf file (keep in mind that we use a moved cache directory - public/cache):
If the http user agent is Mobile Safari, then it won't direct the request to the cached page.
The final hurdle was to make sure that people couldn't access the iPhone version of the site if they didn't have an iPhone or iPod Touch. Again, it was as simple as adding another RewriteRule.
----------------------------------
If you have an iPhone or iPod Touch, you can access the optimized version of this site at http://iphone.plexusweb.com.











