Created
April 25, 2013 13:21
-
-
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.
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
# 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