UserAgent is information about the WEB usage environment included in the HTTP request header. It contains information such as browser type, browser version, and device OS type.
The HTTP request header is additional information sent together with the request information sent from the browser to the website when the website is accessed. There is information such as UserAgent, Referer (link source URL), Authorization (authentication information).
The Rails controller has an accessor method that points to the request object. By using it, you can easily get UserAgent in the controller as follows.
request.user_agent
Request information can be easily obtained by using the request object as shown below.
request.url #The entire URL used in the request
request.remote_ip #IP address of the client
request.query_string #URL query character
(reference) [Rails Guide: request object and response object](https://railsguides.jp/action_controller_overview.html#request%E3%82%AA%E3%83%96%E3%82%B8%E3%82%A7%E3 % 82% AF% E3% 83% 88% E3% 81% A8response% E3% 82% AA% E3% 83% 96% E3% 82% B8% E3% 82% A7% E3% 82% AF% E3% 83 % 88)
Recommended Posts