This is the 7th video in the Getting Started with Rails 7 series. In this video Mike adds tests and implements the create
and new
methods for the Article
resource, allowing for the creation of an Article
record via the application. Following the guide, he first implements create
with hardcoded values for the title
and body
attributes, then implements the new
action with the form_with
helper. After both of those are created, he uses strong parameters and wires up the form to create Article
records dynamically.
This video covers:
- 00:00:10 Introduction
- 00:02:32 Add POST create test to
ArticlesControllerTest
- 00:04:14 Add
create
action toArticlesController
and modify to make the test pass - 00:06:27 Talk through guide explanation of the
new
action instantiating an instance ofArticle
andcreate
actually saving to the database - 00:08:24 Invoke the
create
action from curl. Note: In the video we temporarily disableverify_authenticity_token
in our local to demonstrate quickly. DO NOT do this in a real app! - 00:11:21 Redirect vs. render in the
create
action - 00:13:30 Write failing test for
new
action - 00:15:16 Create the
new
action in the controller - 00:16:06 Create blank
new.html.erb
. Test now failing instead of erroring - 00:16:50 Review the new form builder and
form_with
method and add to view template - 00:19:37 Look at the
new
action in the app. Test passing butcreate
action still hardcoded - 00:20:40 The requirement for strong parameters to allow only the attributes you specify
- 00:22:12 Modify the
ArticlesControllerTest
to use parameters - 00:23:50 Add article_params private method to
ArticlesController
- 00:25:32 Tests are passing. Create works in the application!
- 00:28:16 Commit and push the code
The code for this series is open source and available on GitHub. View the commit for this video here.