Skip to content

Instantly share code, notes, and snippets.

@kagemusha
Created February 27, 2012 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kagemusha/1920839 to your computer and use it in GitHub Desktop.
Save kagemusha/1920839 to your computer and use it in GitHub Desktop.
Rails Mobile web app setup
Rails 3.2
1. In initializers/mime_types.rb
2. Detection of Mobile Device
I put this is a file called mobile.rb in app/util
module Mobile
#optional for testing
TEST_MOBILE_DEV = false #set true to test on browser
MOBILE_PROD_OVERRIDE = false #test on browser in prod
def mobile_device?
mobileClient = request.user_agent =~ /Mobile|webOS/
MOBILE_PROD_OVERRIDE or mobileClient or (TEST_MOBILE_DEV and !Site.production?)
end
def mobile
request.format = :mobile if mobile_device?
end
end
3. Controller before_filter
class ApplicationController < ActionController::Base
protect_from_forgery
...
before_filter :mobile
helper_method :mobile_device?, :current_user
...
4. Views: application.mobile.haml (or application.mobile.html)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment