Skip to content

Instantly share code, notes, and snippets.

@keithnorm
Created June 24, 2010 20:39
Show Gist options
  • Select an option

  • Save keithnorm/451937 to your computer and use it in GitHub Desktop.

Select an option

Save keithnorm/451937 to your computer and use it in GitHub Desktop.
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