Stateless Code | Codecast: Getting Started with Rails 7 08: Model Validations and Form Error Messages @StatelessCode | Uploaded December 2021 | Updated October 2024, 4 hours ago.
This is the 8th video in the Getting Started with Rails 7 series. In this video Mike demonstrates that you can currently create an Article record with an empty title and body. In order to solve the problem, he uses Rails model validations to ensure the data for the Article record is in good order before trying to save to the database. He first creates failing tests in the ArticleTest model test class and then adds in the validations to make them pass. After that, he adds embedded Ruby to the new view template to display the error messages in the view if any exist.
This video covers:
00:00:10 Introduction and demonstrate lack of validations
00:02:55 Write failing model tests in ArticleTest class, both happy and unhappy paths
00:09:13 Add validations to the article model incrementally to make tests pass
00:11:27 Review the validation error message view code in the guide
00:17:30 Add test for bad parameters to ArticlesControllerTest and troubleshoot assert_select unexpected behavior. Solve by adding classes to the error message divs.
00:24:10 Add back in the error messages to the view to make the tests pass and explore in the application UI
00:25:05 Review the rest of this section of the guide. Demonstrate preservation of bad form input data if invalid
00:25:50 Add link_to helper in articles index view to new article form
00:29:11 Review, commit, and push the code
This video is CC0 - No rights reserved. (YouTube doesn't allow this option when publishing.) All code is released under the UNLICENSE. Stateless Code denies the concept of "intellectual property". Copying is not stealing.
This is the 8th video in the Getting Started with Rails 7 series. In this video Mike demonstrates that you can currently create an Article record with an empty title and body. In order to solve the problem, he uses Rails model validations to ensure the data for the Article record is in good order before trying to save to the database. He first creates failing tests in the ArticleTest model test class and then adds in the validations to make them pass. After that, he adds embedded Ruby to the new view template to display the error messages in the view if any exist.
This video covers:
00:00:10 Introduction and demonstrate lack of validations
00:02:55 Write failing model tests in ArticleTest class, both happy and unhappy paths
00:09:13 Add validations to the article model incrementally to make tests pass
00:11:27 Review the validation error message view code in the guide
00:17:30 Add test for bad parameters to ArticlesControllerTest and troubleshoot assert_select unexpected behavior. Solve by adding classes to the error message divs.
00:24:10 Add back in the error messages to the view to make the tests pass and explore in the application UI
00:25:05 Review the rest of this section of the guide. Demonstrate preservation of bad form input data if invalid
00:25:50 Add link_to helper in articles index view to new article form
00:29:11 Review, commit, and push the code
This video is CC0 - No rights reserved. (YouTube doesn't allow this option when publishing.) All code is released under the UNLICENSE. Stateless Code denies the concept of "intellectual property". Copying is not stealing.