New to ruby on rails, trying to get this url structure:
/about
/about/staff
/about/contact
/about/brazil
/about/brazil/staff
/about/brazil/contact
When I do:
rails generate controller about index
rails generate controller about staff
rails generate controller about contact
I set my routes to:
get "about", :to => "about#index"
get "about/staff", :to => "about#staff"
get "about/contact", :to => "about#contact"
And all is well, but I got stumped when I need to do the same for a third level for the brazil office
Should I just do
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"
Or is there a cleaner way to accomplish this?
I think you want to call this
rails generate controller About index staff contactto generate
AboutControllerwith three actionsindex,staffandcontact. Then you want to allow passing in id parameter as the second path element:Then in
config/routes.rb:When I check routes with
rake routesI see now:You can now request http://localhost:3000/about/brazil/staff and the value of params[:id] will be “brazil”.