how to detect browser, os and source using user_agent

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.

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.

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