how to detect browser, os and source using user_agent


#1

When i printed

request.user_agent

its giving:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36

I need to a way to separate browser, os, devise from the above answer and store the in database.


#2

You can parse the line for Macintosh … but IMO it’s not going to work well when faced with the general population of user_agent strings. Many bot’s lie and not all browsers are consistent.


#3

Well, thanks for the response, i have done this using agent_orange gem.