This course will be retired on June 1, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
We have routes leading to seven action methods on our controller... It took us seven lines of code in our routes.rb file to set all these routes up. But because these are the seven conventional routes for any given Rails resource, and you're going to need to set up these same seven routes for most resources you create, there's a shortcut you can use instead.
These are the seven conventional routes that almost any Rails resource will have:
Rails.application.routes.draw do
get '/pages', to: 'pages#index'
post '/pages', to: 'pages#create'
get '/pages/new', to: 'pages#new', as: 'new_page'
get '/pages/:id', to: 'pages#show', as: 'page'
get '/pages/:id/edit', to: 'pages#edit', as: 'edit_page'
patch '/pages/:id', to: 'pages#update'
delete '/pages/:id', to: 'pages#destroy'
end
You can replace all of the above with a single line:
Rails.application.routes.draw do
resources :pages
end
resources :pages
will create all the same routes (named in the same way) as the preceding seven lines of code.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up