Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect user agent in Rails 4 - read HTTP header

I just switched from PHP to Ruby on Rails and was wondering if there was a way to detect the clients device/user agent (reading the HTTP header) in order to serve different versions of the site depending on the request it gets. In PHP I have been using Mobile Detect to do so. The general idea is to only serve files that are needed for each particular version. Thats why a client side approach is not that effective.

Is there a way to do something similar with Ruby 2.0.0 and Rails 4.0.0 ?

Maybe there is a gem to handle cases like that?

like image 212
Severin Avatar asked Oct 23 '13 07:10

Severin


1 Answers

Check the request method, where you can get a ActionDispatch::Request where you have all the request parameters, including the user agent.

request.user_agent 
like image 135
Paulo Fidalgo Avatar answered Oct 17 '22 04:10

Paulo Fidalgo