Created
March 27, 2012 14:28
-
-
Save kinopyo/2216400 to your computer and use it in GitHub Desktop.
Rails: Detect if mobile agent
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
# from https://github.com/ruby-china/ruby-china/blob/master/app/helpers/application_helper.rb | |
MOBILE_USER_AGENTS = 'palm|blackberry|nokia|phone|midp|mobi|symbian|chtml|ericsson|minimo|' + | |
'audiovox|motorola|samsung|telit|upg1|windows ce|ucweb|astel|plucker|' + | |
'x320|x240|j2me|sgh|portable|sprint|docomo|kddi|softbank|android|mmp|' + | |
'pdxgw|netfront|xiino|vodafone|portalmmm|sagem|mot-|sie-|ipod|up\\.b|' + | |
'webos|amoi|novarra|cdm|alcatel|pocket|iphone|mobileexplorer|mobile' | |
def mobile? | |
agent_str = request.user_agent.to_s.downcase | |
return false if agent_str =~ /ipad/ | |
agent_str =~ Regexp.new(MOBILE_USER_AGENTS) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could use an update as iPad now uses "macintosh" instead of "ipad". But what you have works.