3

I have the actual request and I would like to know the name of the route that Rails has resolved.

For example, if I have this route:

front_page GET    /front/pages/:id(.:format)

And the actual request is:

/front/pages/10 (GET)

I would like to have as result:

front_page
fguillen
  • 36,125
  • 23
  • 149
  • 210
  • There are similar questions in SO like http://stackoverflow.com/q/1203892/316700 and http://stackoverflow.com/q/5231027/316700 but the are not returning the **route name** – fguillen Aug 04 '13 at 15:31

1 Answers1

3

IMHO you could use the code explained by KinOfCain on How can I find out the current route in Rails?

Rails.application.routes.router.recognize(request){ |route, matches, parameters| puts route.name }

The router is not storing the route recognized in any place at least I wasn't able to find it

Community
  • 1
  • 1
  • @fguillen The same approach does not work [here](http://stackoverflow.com/q/42691729/1610034), any thoughts? – Saurabh Mar 14 '17 at 08:00