I would like to be able to get the name of the current route in the request in Ruby on Rails. I found ways to access the controller and the action of the request, but I would like to access the string or character of the name.
For example, if I have a resource users;
users
users_path
edit_users_path
I just want to get the name of the current route for this request.
The following code will provide you.
Rails.application.routes.recognize_path(request.request_uri)
, , ActionDispatch::Routing::RouteSet ( , Rails.application.routes), . .
ActionDispatch::Routing::RouteSet
Rails.application.routes
URL- , , users_path
request.original_url # => www.mysite.com/users/1 request.request_uri # = > /users/1