Created
February 27, 2012 02:22
-
-
Save kagemusha/1920839 to your computer and use it in GitHub Desktop.
Rails Mobile web app setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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