Rails 3路由:资源和路径

我在我的Rails应用程序中有以下路径:

resources :settings, :path => :account, :only => [:edit, :update]

这创建了以下内容:

edit_setting GET    /account/:id/edit(.:format) settings#edit
setting PUT    /account/:id(.:format) settings#update

我如何编写它以便省略:id

So a user can just access /account/edit

1
额外
意见: 1

2 答案

这可能是最直接的方式,并且让你接近轨道约定:

match 'account/edit'  => 'accounts#edit',   :as => 'edit_account',  :via => :get
match 'accounts'      => 'accounts#update', :as => 'accounts',      :via => :put
3
额外

See http://guides.rubyonrails.org/routing.html#singular-resources for details, but I'm pretty sure resource :settings, :path => :account, :only => [:edit, :update] will work.

2
额外