Created
February 15, 2012 21:50
-
-
Save jmccartie/1839230 to your computer and use it in GitHub Desktop.
Determines whether or not the user is a mobile device
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
def prepare_for_mobile | |
session[:mobile_param] = params[:mobile] if params[:mobile] | |
request.format = :mobile if mobile_device? | |
end | |
def mobile_device? | |
return (session[:mobile_param] == "1") if session[:mobile_param] | |
request.user_agent.to_s.downcase =~ Regexp.new( | |
'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|ipad|iphone|mobileexplorer|' + | |
'mobile' | |
) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment