# Scaffolding w/ existing DB Tables

**URL:** <https://www.ruby-forum.com/t/scaffolding-w-existing-db-tables/173483>\
**Category:** Rails\
**Created:** [August 10, 2009, 11:31am UTC](https://www.ruby-forum.com/t/scaffolding-w-existing-db-tables/173483 "2009-08-10T11:31:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ratking](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9f8e36/32.png) [@ratking](https://www.ruby-forum.com/u/ratking)\
**Post date:** [August 10, 2009, 11:31am UTC](https://www.ruby-forum.com/t/scaffolding-w-existing-db-tables/173483/1 "2009-08-10T11:31:18Z")

</div>

I am sure many people have asked this already… But I could not find  
anything helpful. I am trying to use RoR with an existing database with  
tables already defined.

I used script/generate scaffold account

But when I point to localhost:3000/account, no table columns showed up.  
The “new account” link is there, but no columns nor any content (and I  
have content in my db table). When I click on new account, only the  
create button showed up. When I click on the create button, a new entry  
gets added to my existing db table, with all fields blank!

What’s up with this? It’s obviously able to talk to the DB, but what did  
I do wrong that caused RoR to not able to figure out what fields already  
exist?

My table was named account, but ActiveScaffold insists on using accounts  
as the table name, so I added set\_table\_name “account” to my Model  
class.

I appreciate any help.

Thank you,  
Rat

---

<div class="post-metadata">

**Author:** ![ratking](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9f8e36/32.png) [@ratking](https://www.ruby-forum.com/u/ratking)\
**Post date:** [August 10, 2009, 1:15pm UTC](https://www.ruby-forum.com/t/scaffolding-w-existing-db-tables/173483/2 "2009-08-10T13:15:21Z")

</div>

With scaffolding you can specify the list of fields and its data type.  
Try again this way…

ruby script/generate scaffold Account field1:datatype field2:datatype

let me know if it works.

---

<div class="post-metadata">

**Author:** ![ratking](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9f8e36/32.png) [@ratking](https://www.ruby-forum.com/u/ratking)\
**Post date:** [August 10, 2009, 1:20pm UTC](https://www.ruby-forum.com/t/scaffolding-w-existing-db-tables/173483/3 "2009-08-10T13:20:31Z")

</div>

> I used script/generate scaffold account
> 
> But when I point to localhost:3000/account, no table columns showed up.  
> The “new account” link is there, but no columns nor any content (and I  
> have content in my db table). When I click on new account, only the  
> create button showed up. When I click on the create button, a new entry  
> gets added to my existing db table, with all fields blank!

Hi

this is because you have to do scaffolding with all the columns that  
the current db has. So for example if it has an email field you can do  
like

script/generate scaffold account email:string

Sijo

---

<div class="post-metadata">

**Author:** ![ratking](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9f8e36/32.png) [@ratking](https://www.ruby-forum.com/u/ratking)\
**Post date:** [August 10, 2009, 1:25pm UTC](https://www.ruby-forum.com/t/scaffolding-w-existing-db-tables/173483/4 "2009-08-10T13:25:45Z")

</div>

Rat King wrote:

> I am sure many people have asked this already… But I could not find  
> anything helpful. I am trying to use RoR with an existing database with  
> tables already defined.
> 
> I used script/generate scaffold account
> 
> But when I point to localhost:3000/account, no table columns showed up.  
> The “new account” link is there, but no columns nor any content (and I  
> have content in my db table). When I click on new account, only the  
> create button showed up. When I click on the create button, a new entry  
> gets added to my existing db table, with all fields blank!
> 
> What’s up with this? It’s obviously able to talk to the DB, but what did  
> I do wrong that caused RoR to not able to figure out what fields already  
> exist?
> 
> My table was named account, but ActiveScaffold insists on using accounts  
> as the table name, so I added set\_table\_name “account” to my Model  
> class.
> 
> I appreciate any help.
> 
> Thank you,  
> Rat

In model there is Account (A capital letter) u have change in schema and  
migrate folder bd/ …
