Rails Browser Detection Methods

前端 未结 3 1388
春和景丽
春和景丽 2020-11-30 05:18

Hey Everyone, I was wondering what methods are standard within the industry to do browser detection in Rails? Is there a gem, library or sample code somewhere that can help

相关标签:
3条回答
  • 2020-11-30 06:07

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

    0 讨论(0)
  • 2020-11-30 06:12

    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).

    0 讨论(0)
  • 2020-11-30 06:12

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

    0 讨论(0)
提交回复
热议问题