Skip to content

Getting Started with Rails 7 Episode 26: Fix Rich Text Fixtures and Validations

This is the 26th video in the Getting Started with Rails 7 series. In this video Mike fixes some errors from the Use ActionText for Rich Text Content video (episode 24).

The two main fixes are

  • The rich_texts.yml fixture had the wrong value for all of the name attributes. It should be the name of the rich text field on the record.
  • The validations were removed in the previous video. You can still have validation on rich text fields. You just need to validate with a custom method.

This video covers:

  • 00:00:10 Introduction. Review the bugs.
  • 00:00:40 Fix the fixtures to use the correct field name attribute and check on tests
  • 00:08:53 Restore the validation tests that were removed in the previous video
  • 00:10:17 Add body presence validation back into the Article model
  • 00:11:58 Write custom method to validate length of the rich text body
  • 00:16:55 Refactor body validations into a concern and apply it to the Comment and Article models
  • 00:22:46 Create testing support concern for body validation tests
  • 00:36:15 Test in the browser. Doesn’t work if comment is invalid because we don’t have an unhappy path in the CommentsController.
  • 00:39:35 Implement functionality for if comment fails validation
  • 00:52:18 Review, commit, and push code

The code for this series is open source and available on GitHub. View the commit for this video (shared commit between this video and the previous video) here.

Leave a Reply