Created
June 24, 2010 20:39
-
-
Save keithnorm/451937 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| module App::Controllers::MobileSupport | |
| def self.included(base) | |
| base.send :before_filter, :redirect_to_appropriate_site | |
| base.send :helper_method, :iphone_request? | |
| base.send :helper_method, :touch_request? | |
| end | |
| def redirect_to_appropriate_site | |
| end | |
| def touch_request? | |
| request.subdomains.first.eql?("touch") || android_request? || iphone_request? || palm_pre_request? && user_wants_mobile_site? | |
| end | |
| def android_request? | |
| (request.env["HTTP_USER_AGENT"] || "") =~ /(Android\/.+Safari)/ | |
| end | |
| def iphone_request? | |
| (request.env["HTTP_USER_AGENT"] || "") =~ /(Mobile\/.+Safari)/ | |
| end | |
| def palm_pre_request? | |
| (request.env["HTTP_USER_AGENT"] || "") =~ /(webOS\/.+Safari)/ | |
| end | |
| def user_wants_mobile_site? | |
| (params[:mobile].nil? || params[:mobile].eql?('true')) && | |
| (cookies[:mobile].nil? || cookies[:mobile].eql?('true')) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment