0

User can came from web or from devise (Android|iPhone|iPad|iPod) How correctly detect it?

Oksana
  • 13,442
  • 10
  • 53
  • 89

2 Answers2

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.

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
)