Ruby-on-rails 有没有办法在 Rails 3.1 中检测用户代理

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7650799/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 02:06:12  来源:igfitidea点击:

Is there a way to detect user agent in Rails 3.1

ruby-on-railsrubybrowseruser-agent

提问by Dani?l Zwijnenburg

Possible Duplicate:
Auto detect mobile browser (via user-agent?)
Rails 3: HTTP_USER_AGENT

可能重复:
自动检测移动浏览器(通过用户代理?)
Rails 3:HTTP_USER_AGENT

Is there a way to detect the user agent from a current visitor? I'm currently working on a project to display video files. But for the ipad, iphone / samsung galaxy tab / internet explorer / firefox. I need to display video's is there a solid way to check which browser is visiting my rails app?

有没有办法从当前访问者中检测用户代理?我目前正在研究一个显示视频文件的项目。但对于 ipad、iphone / 三星 Galaxy Tab / Internet Explorer / firefox。我需要显示视频是否有可靠的方法来检查哪个浏览器正在访问我的 rails 应用程序?

Thanks guys!

谢谢你们!

回答by CambridgeMike

Yep, just use this

是的,就用这个

request.env["HTTP_USER_AGENT"]
#or
request.user_agent

回答by Nicolas Guillaume

What about using a simple gem?

使用简单的 gem 怎么样?

If I remember well, I used this one last time.

如果我没记错的话,我上次用过这个。

gem install user-agent

gem 安装用户代理

The same one on GitHub

GitHub 上的同一个

I think that this is a good way to do it...

我认为这是一个很好的方法来做到这一点......

回答by server info

you can do it also client site with jquery ... there is a plugin

你也可以用jquery来做客户端站点......有一个插件

http://plugins.jquery.com/project/client-detect

http://plugins.jquery.com/project/client-detect