To scaffold or not to scaffold?

I’ve used a number of resources to teach myself Rails over the past few years. I’ve used both the Intro to Rails workshop here on learn as well as Agile Web Development with Rails book from the PragmaticProgrammers.

The major difference in these two tutorials was the use of scaffolding to build the initial CRUD framework. The Prag Prog book used scaffolding while the learn workshop didn’t. I actually really appreciated that the learn workshop made me do the work myself as it gave me deeper understanding of how the pieces all fit together.

Given that, what is the general thought on using scaffolding in a real-life project? Do you generally use the base scaffolding and throw out what you don’t need or do you build the controller infrastructure from scratch. Or (the likely answer), does it just depend upon the nature of the controller you are implementing?

Any insights on how you use the scaffolding generation would be appreciated.

I never use scaffolding.

I do, however, sometimes use a gem like rails_admin to provide the simple CRUD functionality of an admin area.

2 Likes

I think the advantage of writing the code yourself, instead of using rails scaffolding, is that you only get the code and functionality you asked for.

When you use a lot of Rails scaffolding, you loose sight of your codebase and get a lot of code you didn’t ask for and you’re unaware of.

The only generators I use is for creating Rails migrations

2 Likes

I also have stayed away from using scaffolding. In addition to the reasons already mentioned above when using TDD you only want to generate enough code to satisfy the tests you have written. When generating with scaffolding you most likely end up with more code than you have tests for and have to go back and retroactively write the tests or remove the code you don’t need. I’ve so far enjoyed following the workflow of incrementally building your app to satisfy your tests as outlined in the TDD workshop.

I tried ONE app (a little itty bitty practice app) using scaffolding. It’s the easy way of throwing together a simple app in a hurry, BUT there’s a trade-off: with scaffolding, it can be more complicated to customize the app. I use Rails generators to generate models and controllers and migrations. But to just do the scaffold thing in one fell swoop, I am leaving that alone for now.

Scaffolding is useful while prototyping. If you want to get a general feeling of what an implementation will look like before you start trying to implement it, you can spike it out using scaffolds and a little glue code. However, I always throw away this code once I’m done prototyping before I start on a production-ready implementation.

@jferris That’s a great suggestion. I like the idea of building a small prototype with scaffolding just to get an understanding of the problem space. It really makes sense to throw that way before moving forward.