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
When we submit our form for a new Page, we see the error "No route matches [POST] '/pages'". Notice that it's not saying [GET] '/pages', it's saying POST. We only have GET request routes for pages right now, though. We'll need to add a POST route.
When you're adding new data to the server, your browser sends an HTTP POST request. So, when you click the submit button on an HTML form, that's what your browser sends to the server: a POST request with the form contents.
For this reason, setting up a form to add new instances of a resource usually requires two routes in your routes.rb
file.
Suppose we were setting up a form for new Page
records. We'd first need a route to GET the HTML form:
get '/pages/new', to: 'pages#new'
Then we'd need a second route to accept the POST request when the form is submitted:
post '/pages', to: 'pages#create'
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