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've successfully created a form for editing an existing Page, and populated it with the Page's attributes. But if we submit the form, we see that a so-called HTTP PATCH request is being sent by the browser, and there's no route for that type of request. So to process these requests, we'll need to go into routes.rb add a PATCH route.
A controller action to update an existing model object usually performs these operations:
def update
# Look up the existing model record based
# on an ID from the request path.
@page = Page.find(params[:id])
# Filter the form parameters to ensure no
# malicious parameters were added.
page_params = params.require(:page).permit(:title, :body, :slug)
# Use the filtered parameters to update
# the existing model record.
@page.update(page_parameters)
# Redirect the browser to another location
# so that it doesn't just sit there displaying
# the submitted form.
redirect_to @page
end
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