How to get “User Agent” in a request?

Try request.env['HTTP_USER_AGENT'] in your controller.

Or just request.user_agent.

Practice

If we wanna handle the special business logic on Mobile side. The simplest way to seperate the request is using user agent. Like the follows

if request.user_agent =~ /Mobile/
  # DO THE MOBILE LOGIC
else
  # DO OTHER THINGS
end