-
-
Save mattpuchlerz/451965 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 | |
| if on_touch_site? and requesting_full_site? | |
| redirect_to 'www...' | |
| elsif on_full_site? and requesting_touch_site? | |
| redirect_to 'touch...' | |
| end | |
| end | |
| def on_touch_site? | |
| request.subdomains.first == 'touch' | |
| end | |
| def on_full_site? | |
| request.subdomains.first == 'www' | |
| 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 requesting_touch_site? | |
| params[:mobile] == 'true' or | |
| ( params[:mobile].nil? && cookies[:mobile] == 'true' ) or | |
| android_request? or | |
| iphone_request? or | |
| palm_pre_request? | |
| end | |
| def requesting_full_site? | |
| params[:mobile] == 'false' | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment