Skip to content

Instantly share code, notes, and snippets.

@jhammann
Created April 25, 2013 13:21
Show Gist options
  • Save jhammann/5459631 to your computer and use it in GitHub Desktop.
Save jhammann/5459631 to your computer and use it in GitHub Desktop.
Ruby code check for mobile devices. The first check covers all mobile devices but with the second one you can be more specific. For instance if you don't want support for iPad's you can just remove 'iPad'. Too bad the same can't be done for Android devices, you cannot exclude tablets or other devices.
# simple mobile check which covers all devices.
def is_mobile?
request.user_agent =~ /Mobile|webOS/
end
# more advanced mobile check, you can exclude devices.
def is_mobile?
request.env["HTTP_USER_AGENT"][/(iPhone|iPad|iPod|BlackBerry|Android)/]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment