Problem with scaffolding?

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 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.

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 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

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

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

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?

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

HTH,

-Roy