This is the 5th video in the Getting Started with Rails 7 series. In this video Mike adds the route, controller action, and view to show a single Article. He also adds testing to cover the functionality and fixes some errors in the previously created fixtures.
This video covers:
- 00:00:10 Introduction
- 00:02:08 Add get articles/:id route to articles#show
- 00:04:15 Update the ArticlesControllerTest for new functionality and iterate through failures. Add as: ‘article’ to routes to get article_url to get new error
- 00:09:37 Add show action to ArticlesController
- 00:10:57 Create show.html.erb to get a failure instead of an error in the test
- 00:12:02 Find and assign the Article in the show method
- 00:13:53 Populate the show.html.erb content. We can now display an Article using the show action
- 00:15:25 Fix the fixture to the the controller test passing
- 00:18:37 Refactor some test code into the setup method.
- 00:19:25 Add a link to the Articles index page for each record and remove as: ‘article’ from routes
- 00:22:51 Fix error of duplication of article title in the index view
- 00:24:13 Review changes. Commit and push code.
As in previous videos, Mike uses a test-driven development approach to show a single Article. He intentionally makes the test pass in small increments to demonstrate the types of errors you might encounter when implementing the show action. Ordinarily you wouldn’t be quite so incremental when writing a real app. However, here the goal is to learn so it’s okay to slow things down and grasp the concepts.
The code for this series is open source and available on GitHub. View the commit for this video here.