문제

I have a basic User class, and each user has a number of has_one associations with other objects (account, profile, etc). I have my routes nested as such:

resources :users do
  resource :account
  resource :profile
end

And that gives me the appropriate routes:

        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

But I want the logged-in user to be able to access their owned objects via URLs like this:

/settings/profile
/settings/account
...etc

How do I need to set up my routes for that?

도움이 되었습니까?

해결책

Use this code in your routes.rb:

resources :users
resource :account, path: 'settings/account'
resource :profile, path: 'settings/profile'
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top