我有一个基本的User类,每个用户都有许多与其他对象(帐户,个人资料等)的has_one关联。我有我的路线嵌套:
resources :users do
resource :account
resource :profile
end
这给了我合适的路线:
user_profile POST /users/:user_id/profile(.:format) profiles#create
new_user_profile GET /users/:user_id/profile/new(.:format) profiles#new
edit_user_profile GET /users/:user_id/profile/edit(.:format) profiles#edit
GET /users/:user_id/profile(.:format) profiles#show
PATCH /users/:user_id/profile(.:format) profiles#update
PUT /users/:user_id/profile(.:format) profiles#update
DELETE /users/:user_id/profile(.:format) profiles#destroy
但是我希望登录用户能够通过以下URL访问他们拥有的对象:
/settings/profile
/settings/account
...etc
我如何为此设置路线?
答案 0 :(得分:1)
在routes.rb
:
resources :users
resource :account, path: 'settings/account'
resource :profile, path: 'settings/profile'