Route to Create Pages1:18 with Jay McGavren
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
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'
You need to sign up for Treehouse in order to download course files.Sign up