User can came from web or from devise (Android|iPhone|iPad|iPod) How correctly detect it?
Asked
Active
Viewed 546 times
0
-
Duplicate of http://stackoverflow.com/questions/1005153/auto-detect-mobile-browser-via-user-agent – karatedog Apr 03 '12 at 11:40
2 Answers
2
Try something like:
if request.user_agent.include?("iPhone") || request.user_agent.include?("Android")
I use this to render a mobile layout in several of my apps.

David McWilliams
- 66
- 2
1
Parsing incoming header 'User-Agent'
in php it is apache_request_headers()
It will return a key-value pair array
For example:
Array
(
[Host] => www.testing.local
[Connection] => keep-alive
[User-Agent] => Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/4.0.206.1 Safari/532.0
[Cache-Control] => max-age=0
[Accept] => application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
[Accept-Encoding] => gzip,deflate,sdch
[Accept-Language] => en-US,en;q=0.8
[Accept-Charset] => ISO-8859-1,utf-8;q=0.7,*;q=0.3
)

Abdyresul Charyev
- 58
- 1
- 8
-
http://user-agents.my-addr.com/user_agent_request/user_agent_examples-and-user_agent_types.php – Abdyresul Charyev Apr 03 '12 at 11:37