Ruby-on-rails:检测操作系统

时间:2013-09-20 02:22:01

标签: ruby-on-rails ruby rubygems operating-system

我想检测客户端正在使用的操作系统。我可以检测它是移动还是桌面。如何检测它是使用IOS还是Android?

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/28.0.1500.52 Chrome/28.0.1500.52 Safari/537.36

Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko)

Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10

1 个答案:

答案 0 :(得分:2)

使用类似浏览器的宝石'或者喜欢它。

https://github.com/fnando/browser

browser = Browser.new(:ua => "some string", :accept_language => "en-us")
browser.name        # readable browser name
browser.version
browser.safari?
browser.opera?
browser.chrome?
browser.mobile?
browser.tablet?
browser.firefox?
browser.ie?
browser.ie6?        # this goes up to 10
browser.modern?     # Webkit, Firefox 17+, IE 9+ and Opera 12+
browser.platform    # return :mac, :windows, :linux or :other
browser.mac?
browser.windows?
browser.linux?
browser.blackberry?
browser.meta        # an array with several attributes
browser.to_s        # the meta info joined by space