[RUBY] Get UserAgent in [Rails] controller

What is UserAgent?

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.

What is an HTTP request header?

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).

How to get UserAgent in Rails

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 object that can be acquired in various ways other than UserAgent

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

Get UserAgent in [Rails] controller
[rails] List of actions defined in Controller
Group_by in Rails
About Rails controller
Get weather forecast from OpenWeatherMap in Rails
Rails logger Get a rough idea in 1 minute
How to separate .scss by controller in Rails
Model association in Rails
Adding columns in Rails
Disable turbolinks in Rails
CSRF measures in Rails
^, $ in Rails regular expression
Use images in Rails
Understand migration in rails
Get cookies in Spring
Split routes.rb in Rails6
Implement markdown in Rails
Use Extend (Concerns) in Rails to standardize Controller processing.
Get location information in Rails and sort in ascending order
Implement application function in Rails
Declarative transaction in Rails #ginzarb
Get EXIF information in Java
Implement follow function in Rails
Japaneseize using i18n with Rails
Implement LTI authentication in Rails
Error in rails db: migrate
[Java] Get KClass in Java [Kotlin]
Gem often used in Rails
Display Flash messages in Rails
View monthly calendar in Rails
Implement import process in Rails
What to do if you get a "302" error in your controller unit test code in Rails
Rails routing controller view relationship
Use multiple checkboxes in Rails6!
Rewrite Routes in Rails Engine
[Rails / Routing] How to refer to the controller in the directory you created
How to get boolean value with jQuery in rails simple form
Rails: Capture regular expressions in emails!
[Rails] Keyword search in multiple tables
[Rails] Session timeout setting in devise
Add a search function in Rails.
Enable jQuery and Bootstrap in Rails 6 (Rails 6)
[rails] Login screen implementation in devise
[Rails] How to write in Japanese
Get PV (views) using Impressionist ~ Rails
[Rails] Unexpected validation error in devise
About the symbol <%%> in Rails erb
[Rails] Use cookies in API mode
Get Null-safe Map values in Java
Implement simple login function in Rails
How to get parameters in Spark
Create a new app in Rails
Ruby on Rails Japanese-English support i18n
OkHttp3 (GET, POST) in Android Studio
Rails6 OmniAuth activestorage Get user image
[Solution] Webpacker :: Manifest :: MissingEntryError in Rails
Implement a contact form in Rails
Remove "assets" and "turbolinks" in "Rails6".
CRUD features and MVC in Rails
How to introduce jQuery in Rails 6
How to get along with Rails