如何使用url_for生成路径中不存在的路径

问题描述 投票:0回答:1

这可能是不可能的,但我想我会问。我需要生成路径文件中不存在的路径。

例如,我希望能够生成:

include Rails.application.routes.url_helpers
url_for(
  {
    :controller => 'accounts',
    :action     => 'index',
    :id         => '123',
    :only_path  => true
  }
) # => "/accounts?id=123"

以上将提出一个ActionController::UrlGenerationError: No route matches

ruby-on-rails routes ruby-on-rails-5
1个回答
0
投票

你不能那样做AFAIK。 url_for从路由图中推断出很多东西,生成的url无论如何都不会起作用。

用例是什么?也许有更好的解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.