Half-Penny For Your Thoughts

rounded down to the nearest cent



Categories


Recent Articles




Computing

Another Use for Rails Scaffolding

Like many people learning Rails, I started off using scaffolding extensively. Then, after a few months of getting familiar with Rails, I figured I was unlikely to have much use for the scaffold generator. It’s a great tool when you’re first learning rails. Later, it becomes a bit like most user-friendly functions: a limiting pain. Fortunately, scaffolding is presented in everything I’d read about rails as a tool, primarily for getting started. After that I turned to the other generators (when I realized there were simpler generators).

And then, a couple of nights ago, I found myself wandering the scaffold generator’s code. Changing a piece here, ripping out a piece there, but for the most part leaving it intact. And then I ran my modiified version. I intend to do so often. And I won’t mind it’s user-friendliness a bit.

For admin areas of sites, I’ve started re-using the same helper functions, layout, arrangement on the page, etc. Since this is all back-end stuff, I needn’t worry making it fit with the public layout of the site, and can focus on functionality over aesthetics. I can also predict pretty well the functions I’ll be using. Now, what I have didn’t look a whole lot like what scaffold produces, but the kinds of things scaffold generates (controller, views, etc) and the way it connects them were very close to what I needed to cease copying and pasting.

So, I changed up the scaffolding code, and voila, in a couple of hours, I have my admin scaffolder. And fortunately, the scaffold generator proved easy to understand and modify (well, mostly).