Skip to content

Instantly share code, notes, and snippets.

@zjfong
Last active October 13, 2016 02:47
Show Gist options
  • Save zjfong/791f146a1bafca954e231eca2f9e7708 to your computer and use it in GitHub Desktop.
Save zjfong/791f146a1bafca954e231eca2f9e7708 to your computer and use it in GitHub Desktop.
Explain Device Detector Gem

#Device Detector Gem User agent parser and device detector

##What is a user agent? A string of data with the device and software that the visitor is using.

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36

##Why use device detector?

  • Send different HTML depending on browser
  • Different browser features

##Setup gem install device_detector

##Example

user_agent = request.env['HTTP_USER_AGENT']
client = DeviceDetector.new(user_agent)

client.name
client.full_version
client.os_name
client.os_full_version
client.device_name
client.device_type
client.known?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment