【发布时间】:2019-04-01 10:17:09
【问题描述】:
这可能是不可能的,但我想我会问。我需要生成路径文件中不存在的路径。
例如我希望能够生成:
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。
【问题讨论】:
-
请显示您的
rails routes输出 -
你可以在你的路由中传递额外的参数,只是不要称之为 id。例如以下路线将转到索引操作,如果您有
ressources accounts:accounts_path(other_id: '123')=> /accounts?other_id='123'(我不是在我的电脑前检查错别字,但你明白这一点:) )
标签: ruby-on-rails routes ruby-on-rails-5