2013-12-11 3 views
0

기본 사용자 클래스가 있고 각 사용자는 다른 개체 (계정, 프로필 등)와 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 

어떻게 경로를 설정해야합니까?

답변

1

사용하여 routes.rb이 코드 :

resources :users 
resource :account, path: 'settings/account' 
resource :profile, path: 'settings/profile'