The verdict on Rails scaffolding

For every tutorial that uses scaffolding, there’s an article that says
you shouldn’t use it in real websites. Supposedly it just serves to
“sketch things out quickly”, “test database connectivity” and other
stuff. Some say you’re not even supposed to use it and then edit it
later. I don’t get why.

What is it about scaffolding that makes it virtually useless? It
generates some code; surely I could just expand on it or “fix” what’s
wrong with it later, right? Apparently not. How is it different from me
making my own CRUD base files and copypasting it into every project?

I just don’t get it.

Feh… pay no mind to the nay-sayers…

I scaffold for proof of concept all the time, then adjust the pieces and
parts to fit the “real” application after I’m sure that’s what the users
were asking for (i.e., after they get to tinker with it in my dev
environment).

Scaffolding adds things you may or may not want. It’s an easy starting
point. Sometimes I use it when I need a very simple crud interface.
BUT I never use much of the generated views and I’m careful to delete
the bits I don’t want and change the rest. It also saves a tiny amount
of effort to generate the scaffold and do a quick add to my
repository. Nothing gets forgotten that way.

I’ve noticed that a lot of beginners seem to get in trouble with
scaffolding. They don’t necessarily know what all the pieces generated
are or how they fit together, so they don’t know what needs changed or
what needs deleted. So they end up with effects they don’t understand.
For beginners I would recommend coding from the ground up by hand
until they reach the level where they KNOW what the scaffold will
produce and how closely it resembles what they really want.

On Nov 25, 4:59 am, Ralph W. [email protected]

[email protected] wrote:

Scaffolding adds things you may or may not want. It’s an easy starting
point. Sometimes I use it when I need a very simple crud interface.
BUT I never use much of the generated views and I’m careful to delete
the bits I don’t want and change the rest. It also saves a tiny amount
of effort to generate the scaffold and do a quick add to my
repository. Nothing gets forgotten that way.

I’ve noticed that a lot of beginners seem to get in trouble with
scaffolding. They don’t necessarily know what all the pieces generated
are or how they fit together, so they don’t know what needs changed or
what needs deleted. So they end up with effects they don’t understand.
For beginners I would recommend coding from the ground up by hand
until they reach the level where they KNOW what the scaffold will
produce and how closely it resembles what they really want.

So, the bottom line is that there’s nothing fundamentally inept about
it, and it’s all up to how you actually use it, right?

So, the bottom line is that there’s nothing fundamentally inept about
it, and it’s all up to how you actually use it, right?

Posted viahttp://www.ruby-forum.com/.

With the caveat that Rails beginners may be better off avoiding it
until their understanding is better.

[email protected] wrote:

So, the bottom line is that there’s nothing fundamentally inept about
it, and it’s all up to how you actually use it, right?

With the caveat that Rails beginners may be better off avoiding it
until their understanding is better.

I’d capitalize MAY. Other believe that Rails’ scaffolding is a very
good
way for beginners to begin to become familiar with the Rails way of
structuring code and tests, of getting working code to begin to become
familiar with topics like routing, etc. IMHO, scaffolding can be a very
useful learning tool. It’s true that not much is typically left when
you’re
‘done’. OTOH, if it helps get you where you’re going …

Best regards,
Bill

First, like everything, scaffolding is a tool, a means to an end. It
can be useful, but can also be misused. I can’t speak for everyone,
but I hate scaffolding because it keeps people from writing tests.
Scaffolding generates test stubs, but it leaves the controller tests
virtually useless. With scaffolding, it’s very hard to do test-driven
development - instead, you’re retrofitting tests to your existing
code.

I’ve found scaffolding to be extremely helpful for beginners learning
Rails, but i’ve seen too many people rely on it to the point where
they can’t start without one. That worries me, but it’s not
necessarily the fault of scaffolding.

Now, some aspects of scaffolding used to be pretty bad. The fact that
it would iterate over the column names to build table headers was
pretty inefficient in a real web app. Some of this has been fixed in
recent versions.

I’ve also found that one of the key reasons people scaffold things
after they already know Rails is because having something else build
the forms for you is really nice. I hate building forms because it’s
tedius, so I extracted the original “let’s look at your database”
scaffolding code from Rails 1.2.3 and made it available as a gem that
just builds forms from your tables.

It’s available at http://scaffoldform.rubyforge.org

That’s just my take on it though.

So, the bottom line is that there’s nothing fundamentally inept about
it, and it’s all up to how you actually use it, right?

I would personally agree with that. Your mileage will ALWAYS vary
depending on the weather conditions, type of fuel used, people in the
car, and cargo inside but … wait, I got off track there. I tend to
use the scaffold to get something up and running and then by the time
I am done I have torn it apart and added my own stuff along with
getting rid of other stuff.

That is all I really use scaffolding for anymore. When I started, I
thought it was the only way to go but now I end up writing more custom
code than scaffold stuff, but many times I’ll end up scaffolding a
resource just to make sure I have my bases covered originally.

One thing I discovered about scaffolding, even as a starting point, is
that if you every want to use nested resources modifying the scaffolding
to fit what is needed is more work, and adds more risk, than just
building what you need from scratch.

Plus as mentioned you’re more likely to write better tests/specs too.

That’s a good point, Brian. And your form scaffold is a great idea; even
rails’ form helpers don’t really take the pain out of building forms,
but to think that I could bypass all of that with a simple command is
mindblowing.

One thing, though: Rails is now 2.2, so that you extracted it from Rails
1.2.3 makes it sound a little too outdated. Do you still use it? Do you
know how compatible with the new rails it still is? I could try it, but
I’m afraid I’m too much of a newbie to be able to really tell if
something’s not quite right, even if it seems to work fine.

But that is undoubtedly a godsend.

On Nov 30, 9:18 am, Robert W. [email protected]
wrote:

One thing I discovered about scaffolding, even as a starting point, is
that if you every want to use nested resources modifying the scaffolding
to fit what is needed is more work, and adds more risk, than just
building what you need from scratch.

That’s actually a fantastic point I was running into for a while until
I decided to clean out the whole controller I had scaffolded and just
wrote it myself and fixed all of the ridiculous problems I had created
for myself.

There is also nothing quite as satisfying to see the cleanness of a
controller after you have built it from scratch.

Plus as mentioned you’re more likely to write better tests/specs too.

Anyone willing to teach me how to use Rspec? Anyone? Bueller?

Meh, I’ll teach you RSpec if you want, but I’'m a bigger fan of
test::unit. Find me on IRC - hoganbp

Ralph:

It works fine. I just stole the generation code from Rails 1.2.3 but
it works fine in Rails 2.x - I have a few things I might want to
change as it goes forward, but I keep my stuff in pretty good shape -
if it’s deprecated I’ll push a final release that says so in the
readme :slight_smile:

I’m always looking for suggestions too.

On Sat, Nov 29, 2008 at 8:34 AM, Ralph W.

Agreed, nice post there… The only thing i’d add to that, is that as
a Rails beginner-becoming-intermediate, I actually really like the
fact that you can get something up relatively quickly and then start
hacking away at it to create an app… I’d also add that unless you
really understand what’s happening in terms of REST, etc. then it’s
near impossible to effectively build a respectable app… I’ve had a
few moments of frustration/disappointment since I’ve created my first
scaffold, but as long as you stay the course, and have some
programming knowledge, it all makes perfect sense eventually…

Hi –

On Tue, 25 Nov 2008, Ralph W. wrote:

making my own CRUD base files and copypasting it into every project?

I just don’t get it.

Here are a few problems I’ve seen, and continue to see, with the
scaffolding.

It leads people to think that Rails is going to be dead easy, and then
they get frustrated or disappointed when it turns out that developing
a Rails app is real development and real programming.

Although it pertains usually to the beginning stages of an
application, it does not play well with the beginning stages of
learning Rails. It presents way, way too much code to be useful to
beginners. The controller files can be a useful “cheat-sheet” for REST
idioms, but only once the basic techniques and principles are
understood.

As you point out, the scaffolding makes you tweak things and remove
wrong things, instead of developing what you actually need. It turns
development into sculpture (remove everything that isn’t your
application!), and introduces anxieties about whether you’re doing
something wrong because you’re changing something fundamental about
the scaffold code, etc.

It presents a very rigid and specific context for the idea of a
“resource” (in the REST sense), which then impedes people from gaining
a broader understanding of what a resource can be. For more on this
problem, see:

http://dablog.rubypal.com/2008/3/23/splitting-hairs-over-resource
http://dablog.rubypal.com/2008/4/24/splitting-hairs-over-resource-part-2

I agree with the point that others have made that if you know exactly
what the scaffolding provides, and you’ve got a situation where that’s
exactly what you need, there’s no harm in using it. If those
particular boilerplate files happen to coincide with what you want,
that’s great. Otherwise, I’d avoid it. There’s no reason to give it
first refusal of your development space, just because it’s there.

David


Rails training from David A. Black and Ruby Power and Light:
INTRO TO RAILS (Jan 12-15), Fort Lauderdale, FL
See http://www.rubypal.com for details
Coming in 2009: The Well-Grounded Rubyist (The Well-Grounded Rubyist)

Thanks David… I’m pretty familiar with that stuff already
thankfully… but cheers for the info… Right now, i’m coming to
grips with what plugins are out there, which ones are the most common/
popular, and how are they best used… I don’t want to be relying on
plugins too much, but then again I don’t want to have to spend time
doing something that’s already been done…

thanks for the link…

Hi –

On Sun, 30 Nov 2008, Nellboy wrote:

Agreed, nice post there… The only thing i’d add to that, is that as
a Rails beginner-becoming-intermediate, I actually really like the
fact that you can get something up relatively quickly and then start
hacking away at it to create an app… I’d also add that unless you
really understand what’s happening in terms of REST, etc. then it’s
near impossible to effectively build a respectable app… I’ve had a
few moments of frustration/disappointment since I’ve created my first
scaffold, but as long as you stay the course, and have some
programming knowledge, it all makes perfect sense eventually…

You might find this interesting – it’s a kind of explanatory
scaffold, so to speak, for REST in Rails:

http://dablog.rubypal.com/2008/11/24/restful-rails-for-the-restless

(Or you might be past the point where it’s useful, but I thought I’d
throw it out there just in case.)

David


Rails training from David A. Black and Ruby Power and Light:
INTRO TO RAILS (Jan 12-15), Fort Lauderdale, FL
See http://www.rubypal.com for details
Coming in 2009: The Well-Grounded Rubyist (The Well-Grounded Rubyist)

Thanks David - great article - most illuminating…
Dave

Ah, that scratched an itch for me–thanks for posting that.

Cheers,

-Roy