Skip to content

Codecast: Getting Started with Rails 7 Episode 11: Use a Scaffold Generator to Quickly Produce a Resource

“Do you mean to tell me that we could have done all the work from the previous ten videos in half an hour?!”

Yes. (But the purpose of the Getting Started with Rails guide is education, so it slowed things down, added them in incrementally, and explained them.)

This is the 11th video in the Getting Started with Rails 7 series. In this video Mike deviates from the guide temporarily to show an alternate way to quickly produce a Rails resource using the Rails scaffold generator. By using the command rails g scaffold Post title:string body:text we get a full equivalent resource with a route, model, controller, views, and generated tests. Once you gain familiarity with how Ruby on Rails works, this will likely be the most frequent way you create resources.

This video covers:

  • 00:00:10 Introduction and review previous episodes
  • 00:02:30 Use the scaffold generator to create the roughly equivalent Post resource inspect terminal output
  • 00:03:59 Review and compare generated scaffold files to existing Article files
  • 00:06:12 Incorporate before_action callback into the existing ArticlesController
  • 00:08:12 Run tests to see current state and fix bad fixture names
  • 00:10:25 Review posts resource in the application
  • 00:11:16 Adapt model and system tests for validations and Turbo confirm
  • 00:15:46 Get tests passing with Turbo and destroy confirmation
  • 00:24:04 Experiment with ArticlesControllerTest and notice. Revert.
  • 00:28:40 Review, commit, and push

The code for this series is open source and available on GitHub. View the commit for this video here.

Leave a Reply