Answer the question
In order to leave comments, you need to log in
How to intercept url_for for named routes?
Hello.
Rails 4.2.3
Task: Add parameters to each link if they are present in the request.
It is solved (as it seemed at first) by an elementary redefinition of url_for.
But as it turns out, this doesn't work for named routes.
Digging deeper into the rails showed that for named routes, the url_for method is called from ActionDispatch::Routing::RouteSet
and not from. ActionDispatch::Routing::UrlFor
You can override it too, but then I do not have access to the request to get the parameters.
Days of digging in Google yielded no results. I found only that in Rails 4 they optimized the generation of routes and now, in order for everything to work as before, you need to set default_url_options with some value. Registered, did not help. And, again, climbing deep into the rails showed that when creating routes in the UrlHelper class, OptimizedUrlHelper is not used, but UrlHelper itself is used
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question