I know I'm a little late here, but this question is one of the best hits when googling "uses url_helpers in routes.rb" and I initially found it when I came across this problem, so I share my solution.
As @martinjlowm noted in his answer, helper URLs cannot be used when creating new routes. However, there is one way to define a redirect route rule using URLs. The fact is that ActionDispatch :: Routing :: Redirection # redirect can take a block (or #call -able), which later (when the user types a route), called by two parameters, params and a request to return a new route, a string. And since the routes are correctly configured at the moment, it is quite possible to call the calling URLs inside the block!
get 'privacypolicy.php', to: redirect { |_params, _request| Rails.application.routes.url_helpers.privacy_policy_path }
In addition, we can use Ruby metaprogramming tools to add sugar:
class UrlHelpersRedirector def self.method_missing(method, *args, **kwargs)
nameless
source share