Skip to content

Instantly share code, notes, and snippets.

@henriqueutsch
Created March 7, 2018 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henriqueutsch/607128bacff2c9c9f02a2ba020eb2745 to your computer and use it in GitHub Desktop.
Save henriqueutsch/607128bacff2c9c9f02a2ba020eb2745 to your computer and use it in GitHub Desktop.
def mobile_device
# user_agent = 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36'
user_agent = request.env['HTTP_USER_AGENT']
client = DeviceDetector.new(user_agent)
client.name # => 'Chrome'
client.full_version # => '30.0.1599.69'
client.os_name # => 'Windows'
client.os_full_version # => '8'
# For many devices, you can also query the device name (usually the model name)
client.device_name # => 'iPhone 5'
# Device types can be one of the following: desktop, smartphone, tablet, console,
# portable media player, tv, car browser, camera
return client.device_type # => 'smartphone'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment