Rails Browser Detection Methods

霸气de小男生 提交于 2019-11-27 04:09:58
Christoph Schiessl

There's library ruby library over at GitHub: https://github.com/gshutler/useragent

I use it myself, and it's working as advertised so far. For your use case, you could probably call the library from within a helper method in your Rails project or something similar.

That said, I'm not completely sure if the HTTP_USER_AGENT is exposed to Rails helper methods. In case it isn't exposed, you could always expose a controller method as a helper (by using AbstractController::Helpers::ClassMethods#helper_method).

Rob

The browser gem is specifically designed for browser detection in Rails.

Try request.env['HTTP_USER_AGENT'], this will return your client's User Agent. There's also a quick helper posted by Hubert Łępicki

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!