Skip to content

Instantly share code, notes, and snippets.

@jmccartie
Created February 15, 2012 21:50
Show Gist options
  • Save jmccartie/1839230 to your computer and use it in GitHub Desktop.
Save jmccartie/1839230 to your computer and use it in GitHub Desktop.
Determines whether or not the user is a mobile device
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