要轉到什麼Rails的要你做什麼,你所要做的就是添加shallow: true
到每個嵌套resources
的:
resources :stores do
resources :locations, shallow: true do
resources :business_hours, shallow: true
end
end
這會產生,因爲他們所說的那樣,「路線與少量的信息來唯一地標識資源」,這是這樣的:
Prefix Verb URI Pattern Controller#Action
location_business_hours GET /locations/:location_id/business_hours(.:format) business_hours#index
business_hour GET /business_hours/:id(.:format) business_hours#show
store_locations GET /stores/:store_id/locations(.:format) locations#index
location GET /locations/:id(.:format) locations#show
stores GET /stores(.:format) stores#index
store GET /stores/:id(.:format) stores#show
爲locations
收集動作,例如。 index
,得到stores
下築巢,因爲locations
屬於stores
,而是確定一個特定的位置,路線引用locations/1
沒有stores/
前綴,因爲你並不需要一個store
ID來標識location
。
這落下下來的樹:識別business_hours
收集動作,你需要的location
小時屬於,而是因爲你有一個location
ID,你並不需要涉及的store
,讓您得到locations/:id/business_hours
。當你想要一組特定的小時時,你不需要location
了,所以你只需要/business_hours/1
。
如果要維持的時間收集路徑的整個層次(即/stores/1/location/2/business_hours
),你需要或者不shallow
你locations
路徑,這將保證其成員的行爲(show
,edit
等)/stores/1/locations/2
下,或者你需要使用更少的Rails的助手手動指定你想要的路徑。