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

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
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 up-
Kian Chakamian
15,410 Points1 Answer
-
Alex Bannon
4,841 Points1 Answer
-
Andrei Burichita
9,989 Points2 Answers
View all discussions for this video
Related 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