Detecting mobile browsers in Rails 3

后端 未结 3 550
逝去的感伤
逝去的感伤 2021-01-03 23:04

I\'m looking to do some mobile-specific layouts in my app, and have been researching ways to detect mobile browsers and serve mobile specific layouts.

I came across

3条回答
  •  时光说笑
    2021-01-03 23:14

    The best way is to use some supported plugin/gem, like browser You're just unable to follow all browsers with their custom user_agents. For example Opera 11.50 has the following user_agent:

    Opera/9.80 (Android 2.3.7; Linux; Opera Mobi/ADR-1111021303; U; en-GB) Presto/2.9.201 Version/11.50
    

    It is totally unrecognizable with

    request.user_agent =~ /Mobile|webOS/ 
    

提交回复
热议问题