# Problem with scaffolding?

**URL:** <https://www.ruby-forum.com/t/problem-with-scaffolding/142466>\
**Category:** Rails\
**Created:** [July 8, 2008, 10:45am UTC](https://www.ruby-forum.com/t/problem-with-scaffolding/142466 "2008-07-08T10:45:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![prabhas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b2d939/32.png) [@prabhas](https://www.ruby-forum.com/u/prabhas)\
**Post date:** [July 8, 2008, 10:45am UTC](https://www.ruby-forum.com/t/problem-with-scaffolding/142466/1 "2008-07-08T10:45:04Z")

</div>

Hi,  
I am using scaffolding to create application quickly. I have already  
created the database and table (there is only one table: products).  
When I use command: ruby script/generate scaffold Product  
I get all the scripts generated. When I direct my browser to URL:  
[http://localhost:3000/products](http://localhost:3000/products) I see only the title of the page like  
‘Listing products’ and a link to create new product. That is obvious  
as there are no products in the table.  
But when I follow link to create new product, it should display me a  
form matching to table columns, isn’t it? But does not show me  
anything there. What I get is title ‘New product’, a button ‘Create’  
and a ‘Back’ link.

Can anyone direct me where I am going wrong with this? Or is there  
anything else needed to do for this?

I guess, somehow the rails is not being able to get the table fields.  
Hence, it is unable to show the form.  
As it gets empty set of table columns, the form displayed is also  
empty.

Please provide some inputs on this.

---

<div class="post-metadata">

**Author:** ![prabhas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b2d939/32.png) [@prabhas](https://www.ruby-forum.com/u/prabhas)\
**Post date:** [July 8, 2008, 11:00am UTC](https://www.ruby-forum.com/t/problem-with-scaffolding/142466/2 "2008-07-08T11:00:27Z")

</div>

Prabhas Gupte wrote:

> Hi,  
> I am using scaffolding to create application quickly. I have already  
> created the database and table (there is only one table: products).  
> When I use command: ruby script/generate scaffold Product  
> I get all the scripts generated. When I direct my browser to URL:  
> [http://localhost:3000/products](http://localhost:3000/products) I see only the title of the page like  
> ‘Listing products’ and a link to create new product. That is obvious  
> as there are no products in the table.  
> But when I follow link to create new product, it should display me a  
> form matching to table columns, isn’t it? But does not show me  
> anything there. What I get is title ‘New product’, a button ‘Create’  
> and a ‘Back’ link.
> 
> Can anyone direct me where I am going wrong with this? Or is there  
> anything else needed to do for this?
> 
> I guess, somehow the rails is not being able to get the table fields.  
> Hence, it is unable to show the form.  
> As it gets empty set of table columns, the form displayed is also  
> empty.
> 
> Please provide some inputs on this.

How did you create your table ? With plain SQL or through migration ?

I believe that the scaffold thing loads columns name from your DB to  
generate dynamic form, that means if a new column appear in your table,  
a new input will appear as well in your form. But if there is not  
column, there is no input.

Maybe you did not use the migration to create and populate your table  
and you should look there first. If you did, then I don’t know what’s  
going wrong.

Guillaume  
[http://www.nomadsper.com](http://www.nomadsper.com)

---

<div class="post-metadata">

**Author:** ![prabhas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b2d939/32.png) [@prabhas](https://www.ruby-forum.com/u/prabhas)\
**Post date:** [July 8, 2008, 11:07am UTC](https://www.ruby-forum.com/t/problem-with-scaffolding/142466/3 "2008-07-08T11:07:26Z")

</div>

On 8 Jul 2008, at 10:00, Guillaume Petit wrote:

> How did you create your table ? With plain SQL or through migration ?
> 
> I believe that the scaffold thing loads columns name from your DB to  
> generate dynamic form, that means if a new column appear in your  
> table,  
> a new input will appear as well in your form. But if there is not  
> column, there is no input.

Not since rails 2 it doesn’t. As of rails 2 if you edit the model then  
you need to update the form appropriately.

Fred

---

<div class="post-metadata">

**Author:** ![prabhas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b2d939/32.png) [@prabhas](https://www.ruby-forum.com/u/prabhas)\
**Post date:** [July 8, 2008, 5:28pm UTC](https://www.ruby-forum.com/t/problem-with-scaffolding/142466/4 "2008-07-08T17:28:09Z")

</div>

The 2.x scaffolding no longer looks for or inspects any existing tables.  
You’ve got to list out the columns & their types on the call to  
generate. So for example:

ruby script/generate scaffold Product name:string source:string  
date\_acquired:date

etc.

HTH,

-Roy

---

<div class="post-metadata">

**Author:** ![prabhas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b2d939/32.png) [@prabhas](https://www.ruby-forum.com/u/prabhas)\
**Post date:** [July 9, 2008, 4:21am UTC](https://www.ruby-forum.com/t/problem-with-scaffolding/142466/5 "2008-07-09T04:21:15Z")

</div>

Thank you very much for your replies!

@ Guillaume  
I have tried both the ways: creating table using migration and using  
SQL as well.

@ Fred  
Are you sure it doen’t work like I expected since rails 2.x?  
Or were you talking about updations to model.  
What if I do not update the model? will it give me the form for the  
first time?

@ Roy  
Does it mean that I need to list all the fields and their types in  
field:type format in the generate command itself?

---

<div class="post-metadata">

**Author:** ![prabhas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b2d939/32.png) [@prabhas](https://www.ruby-forum.com/u/prabhas)\
**Post date:** [July 9, 2008, 2:45pm UTC](https://www.ruby-forum.com/t/problem-with-scaffolding/142466/6 "2008-07-09T14:45:19Z")

</div>

Well, you need to list out all the fields you want to show up on your  
forms. If you miss any, you can always add them in manually of course.

Here’s a past thread where I beat this to death:  
[http://is.gd/P3t](http://is.gd/P3t)

HTH,

-Roy
