How to create a mobile version of your (ruby on rails) site
You have several very useful libraries that do most of the styling / behavior for you:
iWebkit
jQTouch (sencha touch)
iui
We chose for iWebkit, but if you desire a more native feel you might choose jQTouch. The standard browsers on iPhone, Android, palmOS and Blackberry OS6 are all Webkit based. This ensures that sites based on iWebkit will work on all these devices, which is great! Copy the required javascript, images and stylesheets to your public folder.
Next, you have to detect if your user is on a mobile device.
Add the following code to your application controller:
helper_method :mobile_session?, :on_mobile?
def mobile_session?
if session[:mobile_param]
return session[:mobile_param] == “1″
else
return on_mobile?
end
end
def on_mobile?
request.user_agent =~ /Mobile|webOS|BlackBerry|Android|iPhone|Opera Mini/
end
Next, in config/initializers/mime_types.rb add the following:
Mime::Type.register_alias "text/html", :mobile
The only thing left to do now is to create mobile views. The extension for these files is .mobile.erb Look at the examples provided by the framework to see what html to use in your mobile views.
You’re done!
Some last tips:
- You probably want to leave out some pages, and only show the mobile user the core functionality.
- Always include a link to get to the normal site, which is done by appending ?mobile=0 to a link.
Some screenshots of the mobile version of one of our products:

