Rails 3 detect request coming from mobile clients

后端 未结 2 1655
不知归路
不知归路 2021-01-12 18:22

My setup: Rails 3.0.9, Ruby 1.9.2

My app needs to serve up a mobile vs. web layout depending on the request\'s origin. I need to support all the major mobile client

2条回答
  •  一向
    一向 (楼主)
    2021-01-12 18:39

    It will return User Agent.

    request.user_agent =~ /Mobile|Blackberry|Android/ # OR WHATEVER
    

提交回复
热议问题