Reputation: 11811
How do you get the "URI Pattern" (as shown in rake routes
) for the current HTTP request?
/blogs/:blog_id/posts/:id
I'd like to capture performance stats for each route. Need to distinguish between GET /blogs and GET/blogs/5.
Upvotes: 2
Views: 452
Reputation: 309
It's done by Rails.application.routes.router.recognize
. You can use it in a method like this.
def this_requests_pattern(request)
Rails.application.routes.router.recognize(request) do |route|
return route.path.spec.to_s
end
end
Upvotes: 3