Rails Browser Detection Methods

前端 未结 3 1499
春和景丽
春和景丽 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: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).

提交回复
热议问题