新建Ruby on Rails的,試圖讓這個URL結構:如何在Ruby on Rails中添加第三級導航?
/about
/about/staff
/about/contact
/about/brazil
/about/brazil/staff
/about/brazil/contact
當我這樣做:
rails generate controller about index
rails generate controller about staff
rails generate controller about contact
設置我的路線:
get "about", :to => "about#index"
get "about/staff", :to => "about#staff"
get "about/contact", :to => "about#contact"
,一切都很好,但是當我需要爲巴西辦公室的第三層做同樣的事情時,我很難過。
我應該怎麼做
rails generate controller about brazil_index
rails generate controller about brazil_staff
rails generate controller about brazil_contact
get "about/brazil", :to => "about#brazil_index"
get "about/brazil/staff", :to => "about#brazil_staff"
get "about/brazil/contact", :to => "about#brazil_contact"
還是有一個更清潔的方法來實現這個目標?
這很好,但我建議使用param name':country'而不是':id'像這樣:'get'about /:country/index「' - 這樣你就可以訪問國家值爲'params [:country]'而不是'params [:id]'。 –
感謝你們倆!這就是我一直在尋找的 – chrisan