如何改变单一路径资源的路径?

时间:2012-04-03 09:45:17

标签: ruby-on-rails

在我的路线中,我有:

resources :accounts

这会产生:

    accounts GET    /accounts(.:format)          accounts#index
             POST   /accounts(.:format)          accounts#create
 new_account GET    /accounts/new(.:format)      accounts#new
edit_account GET    /accounts/:id/edit(.:format) accounts#edit
     account GET    /accounts/:id(.:format)      accounts#show
             PUT    /accounts/:id(.:format)      accounts#update
             DELETE /accounts/:id(.:format)      accounts#destroy

我只想更改以下资源路径:

 new_account GET    /accounts/new(.:format)      accounts#new

 new_account GET    /register(.:format)      accounts#new

这可能吗?

2 个答案:

答案 0 :(得分:1)

是的,您可以将控制器中的任何操作与特定路线匹配。

只需将该行添加到routes.rb

即可
match "/register" => "accounts#new"

答案 1 :(得分:0)

您在routes.rb

中尝试这一行
match 'register' => 'accounts#new'