ruby-on-rails-3 - Rails 3:HTTP_USER_AGENT

标签 ruby-on-rails-3 user-agent

我正在努力检测站点上的用户代理以获得技术支持,以便用户无需自己查找它。到目前为止,这就是我所得到的,但是无论我在哪种浏览器上对其进行测试,它都将显示为默认的“未知”。关于我出了问题的任何建议吗?

def cyberbrowser
    mybrowser = ENV["HTTP_USER_AGENT"] 
       case mybrowser 
         when /MSIE 8.0/ then "Internet Explorer V8" 
         when /MSIE 7.0/ then "Internet Explorer V7" 
         when /MSIE 6.0/ then "Internet Explorer V6.0+" 
         when /MSIE 5.5/ then "Internet Explorer V5.5" 
         when /MSIE 5.22/ then "Internet Explorer V5.22" 
         when /MSIE 5.0/ then "Internet Explorer V5.0+" 
         when /MSIE 4.0/ then "Internet Explorer V4.0+" 
         when /MSIE 3.0/ then "Internet Explorer V3.0+" 
         when /MSIE 2.0/ then "Internet Explorer V2.0+" 
         when /Firefox/ then "Mozilla Firefox"
         when /Camino/ then "Camino"
         when /Dillo/ then "Dillo"
         when /Epiphany/ then "Epiphany"
         when /Firebird/ then "Mozilla Firebird"
         when /Thunderbird/ then "Mozilla Thunderbird"
         when /Galeon/ then "Mozilla Galeon"
         when /IBrowse/ then "IBrowse"
         when /iCab/ then "iCab"
         when /K-Meleon/ then "K-Meleon"
         when /Konqueror/ then "Konqueror"
         when /SeaMonkey/ then "SeaMonkey"
         when /Netscape/ then "Netscape"
         when /OmniWeb/ then "OmniWeb"
         when /Opera/ then "Opera"
         when /Safari/ then "Safari"
         else  "Unknown"  
       end
end

最佳答案

在 Controller 中尝试request.env['HTTP_USER_AGENT']。如果这在您的模型中,请将其传递给您的模型。

关于ruby-on-rails-3 - Rails 3:HTTP_USER_AGENT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5226946/

相关文章:

ruby-on-rails - 使用 passenger 在 Apache 上设置 Rails 应用程序 - Rails 似乎无法加载

ruby - 如何在 ruby​​ 中获取 ip 地址、referer 和用户代理?

javascript - 为什么我不能通过循环数组来搜索 UserAgent 的值

html - 默认 CSS 的浏览器依赖于什么?

ssl - nginx多一个ssl配置

ruby-on-rails-3 - Rails 3 和 Devise 的论坛解决方案?

ruby-on-rails - 我如何跳过前三行而不是 FasterCSV 中的第一行

ruby-on-rails-3 - 我怎样才能让 sencha 架构师从 Rails 中读取 json

javascript - iOS 版 Chrome 中附加到用户代理字符串的唯一标签 ID?

ruby - 将两个添加到数组中的元素并显示总和