Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.

share|improve this question

5 Answers 5

up vote 6 down vote accepted

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.

share|improve this answer
    
True that. I'll go ahead and use scaffolding for learning the language and framework quickly. Thanks :) –  Deepak Mittal Jun 24 '11 at 10:36

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?

share|improve this answer
    
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. –  Deepak Mittal Jun 24 '11 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 '11 at 8:07

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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