0

I am new to rails framework. I am confused that what is the benefit of generating scaffold instead of creating tables and columns in DB manually.What is the best for creating rich relational databases in Rails? And can I do bit advance things using scaffold i.e: changing the name of table and column after creating it. Restricting some fields to be private (scaffold should not generate a field in view for that particular private field)

Please explain this to me as I know very little about it! Thanks in advance.

Zain Zafar
  • 1,607
  • 4
  • 14
  • 23

1 Answers1

3

The purpose of scaffolding is to get some boilerplate code quickly. By typing one small command you get model, migrations, views, controller and what not. Now you can tweak the views, for example (or migrations or anything else). Or leave them be if it's some prototype. At least, you didn't have to spend 4 hours creating everything by hand.

Imagine that you start a new blog application. You'll need posts, comments, users, categories. Without scaffolding this is easily a day of work. With scaffolding - two minutes.

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
  • You said that scaffold do migrations too. But I have to manually migrate the DB after generating models by scaffold. Why was that? – Zain Zafar Oct 29 '13 at 08:57
  • Scaffolds create files (migration files among them). Doing actual migration is not its job, it's yours. – Sergio Tulentsev Oct 29 '13 at 08:58
  • Yes Sergio said it. You get something basic up pretty quickly, but it comes at the cost of it being all boiler-plate, and it being a little difficult to change later on. – BenKoshy May 11 '17 at 03:27