A
A
Anton Ivanov2015-06-28 23:02:02
Ruby on Rails
Anton Ivanov, 2015-06-28 23:02:02

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::RouteSetand 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

1 answer(s)
V
vsuhachev, 2015-06-29
@vsuhachev

There is too little magic in rails, more needs to be added, so that the routing helpers give out something that the loser maintaining your code will not expect at all.
PS: sorry, hurt

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question