Rails 3帮助匹配路线

时间:2015-05-11 10:49:07

标签: ruby-on-rails ruby-on-rails-3 rails-routing

在轨道3中,匹配路由后的应用程序在routes.rb中定义

match 'accounts/:account_type/:account_id/edit_account' => 'accounts#edit_account'

在控制器中我重定向到此网址

redirect_to "/accounts/account/#{account_id.to_s}/edit_account"

它工作正常,但我需要一个路由助手而不是手动构建这样的URL

edit_account_accounts_path(account_id: id, account_type: 'some_type')

有没有办法做到这一点?

1 个答案:

答案 0 :(得分:1)

你可以尝试

match 'accounts/:account_type/:account_id/edit_account', to: 'accounts#edit_account', as: 'edit_account_accounts'

获取更多帮助,请参阅The Lowdown on Routes in Rails 3