Scott's Recipes Logo

Rails Scaffold Examples

Pizza courtesy of Pizza for Ukraine!

Donate Now to Pizza for Ukraine

 

Last Updated On: 2025-09-01 04:31:52 -0400

Every so often you discover new aspects to something you have used forever. For myself, I have recently discovered the zen of using Rails scaffold. Now I’ve used rails forever and always used the generators but I’ve never bothered with specifying the data structure fields at the command line – I always just edited the migration file directly.

In this blog post, I’ve documented a number of examples of how you use rails scaffold.

When you Make an Error: rails destroy and rails db:rollback STEP=1

When you go down this route, you’re going to often realize “oh crap I left out a field or it should be named different”. That’s ok – you can easily walk these things back:

When you need to destroy everything:

rails destroy scaffold name

where name was the object you just scaffolded. So if you did:

rails g scaffold Link

to get rid of it you would do:

rails destroy scaffold Link

The above works when you haven’t already run the database migration – if you have then you need to first rollback the migration before the destroy step:

rails db:rollback STEP=1

This will undo the migration, drop the table, etc. Once you’ve done that, you can either modify the migration or destroy everything, recreate it and then re-migrate it.

Scaffold Examples