3

I'm learning Ruby on Rails for a new project of mine. I am referring the book 'Agile Web Development with Rails' which shows how to build a shopping cart and they use scaffolding.

I'm pretty familiar with MVC architecture and have used several frameworks in PHP to build applications. I've never used scaffolding and I'm not sure if that's the best way to start building an application.

Experienced users, please suggest if I should be using scaffolding or should I code manually.

5 Answers 5

5

Go ahead and use scaffolding. Scaffolding is just a way to get some working code quickly. It's not a commitment. Often the hardest part with a new technology is getting the first thing working. RoR scaffolding gets you over that hurdle, and then you can replace or extend the scaffold code bit by bit.

1
  • True that. I'll go ahead and use scaffolding for learning the language and framework quickly. Thanks :) Jun 24, 2011 at 10:36
2

As you are a beginner you should use it. Because you may not all the syntax in that case scaffolding can help you out. I generally use it. Because it saves lot of time as it generate good amount of code and in most case error free. So I will suggest you to use scaffolding in RoR. And the generated is easy to understand so can update it as your need.

Why to do it manually when it can be done automatically which saves time?

2
  • I feared if the code generated would be difficult to modify. I've had bad experiences with modifying other's code. Thanks, I'll use scaffolding. Jun 24, 2011 at 7:58
  • @dpacmittal: Don't worry. The generated code is very simple and you will easily understand it and can easily modify it. And if you still get problem in it then feel free to discuss about problem.
    – Harry Joy
    Jun 24, 2011 at 8:07
1

One of the key reasons is that it will create the database stuff (CRUD) for you. You won't have to write the same boring code every time you want to generate a new model.

Also, if you're using Rails 3 or later, the scaffold produces less redundant code (when it comes to view forms) than 2.x.x, if I'm not mistaken.

The other generators are also useful, I would recommend using them as much as possible.

1

Use it while learning, but understand what it does so you don't rely on it. In many cases using the scaffold will help you get the app up and running quickly (and you can always modify it later and take out the parts you don't need), but make sure that you know how to do it by hand if you need to fix things with the scaffold or if you need to later do something that doesn't require the scaffold.

In short: Scaffolding is a tool, not a crutch, and should be treated like a tool in your arsenal.

0

There's good and bad ways to do scaffolding. I strongly discourage anyone using the default rails scaffolds—the HTML it produces isn't particularly good, and its static.

What I do recommend is the use of something like formtastic to do your scaffolds. You can start with something as simple as

<%= semantic_form_for @model do |form| %>
  <%= form.inputs %>
  <%= form.buttons %>
<% end %>

and get something that's at least as functional as the default scaffolds, and a heck of a lot smarter. you can easily grow into an actual application with it just by replacing the form.inputs with a more defined set of fields you want to appear.

Not the answer you're looking for? Browse other questions tagged or ask your own question.