# Basic Rails 2.0 scaffold and commands question

**URL:** <https://www.ruby-forum.com/t/basic-rails-2-0-scaffold-and-commands-question/135107>\
**Category:** Rails\
**Created:** [April 17, 2008, 11:26pm UTC](https://www.ruby-forum.com/t/basic-rails-2-0-scaffold-and-commands-question/135107 "2008-04-17T23:26:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kellygreer1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/77aa72/32.png) [@kellygreer1](https://www.ruby-forum.com/u/kellygreer1)\
**Post date:** [April 17, 2008, 11:26pm UTC](https://www.ruby-forum.com/t/basic-rails-2-0-scaffold-and-commands-question/135107/1 "2008-04-17T23:26:02Z")

</div>

Sorry if this a supper newb question…  
I’m trying to figure out how when I write:

```
  ruby script/generate scaffold post name:string description:text

```

this generates model, controller, views, etc…  
But when I try to back into a table I already have and write:

```
   ruby script/generate scaffold project

```

I get no controller. ???  
Then if I run:

```
  ruby script/generate controller projects

```

I get a empty controller. What is the right series of commands to get  
a “scaffold’d” controller when you already have a table?

Thanks,  
Kelly Greer  
removed\_email\_address@domain.invalid  
change nospam to yahoo

---

<div class="post-metadata">

**Author:** ![kellygreer1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/77aa72/32.png) [@kellygreer1](https://www.ruby-forum.com/u/kellygreer1)\
**Post date:** [April 18, 2008, 12:17am UTC](https://www.ruby-forum.com/t/basic-rails-2-0-scaffold-and-commands-question/135107/2 "2008-04-18T00:17:05Z")

</div>

um… no reason that shouldn’t work unless you already have a file  
named projects\_controller.rb in the app/controller directory

---

<div class="post-metadata">

**Author:** ![kellygreer1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/77aa72/32.png) [@kellygreer1](https://www.ruby-forum.com/u/kellygreer1)\
**Post date:** [April 18, 2008, 12:33am UTC](https://www.ruby-forum.com/t/basic-rails-2-0-scaffold-and-commands-question/135107/3 "2008-04-18T00:33:28Z")

</div>

Nope. no file there. Is there another file somewhere that tells it  
not to do the controller?  
something else I should delete and then rerun?

Is there a switch to force the standard actions into a "generate  
controller"ed controller?

Thanks,  
Kelly

On Apr 17, 6:16 pm, “removed\_email\_address@domain.invalid” \<ESPN3.DL-

---

<div class="post-metadata">

**Author:** ![kellygreer1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/77aa72/32.png) [@kellygreer1](https://www.ruby-forum.com/u/kellygreer1)\
**Post date:** [April 18, 2008, 5:08pm UTC](https://www.ruby-forum.com/t/basic-rails-2-0-scaffold-and-commands-question/135107/4 "2008-04-18T17:08:22Z")

</div>

You can append --skip-migration when you’re generating a scaffold for  
an existing table.

There isn’t really any ‘introspection’ being done with the generator.  
You simply get the fields/references that you pass to scaffold. If  
you don’t pass any… you don’t get any in the view(s).

Note that the whole idea of a scaffold is something that is intended  
to simply be a placeholder that you’ll remove later (where “removal”  
may mean modification and fine tuning). With that in mind you’re  
probably going spend a lot more time trying to trick scaffolding to do  
what you’re after than it’s worth. For these tables I’d suggest hand  
writing (or copy&paste) the markup and moving on.

---

<div class="post-metadata">

**Author:** ![kellygreer1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/77aa72/32.png) [@kellygreer1](https://www.ruby-forum.com/u/kellygreer1)\
**Post date:** [April 18, 2008, 8:20pm UTC](https://www.ruby-forum.com/t/basic-rails-2-0-scaffold-and-commands-question/135107/5 "2008-04-18T20:20:46Z")

</div>

Am I right in thinking this worked a little different previous to  
Rails 2.0?

I have a project coming up where the model needs to have 35 to 40  
fields.  
Do I really need to append all these fields and types onto the end of  
the scaffold command?  
ouch!

Kelly

---

<div class="post-metadata">

**Author:** ![kellygreer1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/77aa72/32.png) [@kellygreer1](https://www.ruby-forum.com/u/kellygreer1)\
**Post date:** [April 19, 2008, 3:10am UTC](https://www.ruby-forum.com/t/basic-rails-2-0-scaffold-and-commands-question/135107/6 "2008-04-19T03:10:51Z")

</div>

Sort of… Yes, Rails 1.x had a ‘scaffold’ command that would  
dynamically render a form like the one you’d get when you ran script/  
generate scaffold. But I’d also say “No” in the sense that scaffolded  
forms were never intended for production (which is probably why the  
command was deprecated).

A model with 35-40 fields sounds like a model desperately in need of  
refactoring. A good model should have most of its fields in use by  
most of it’s instances. A model with 35-40 sounds like one that has  
several sets of fields that are generally used together in certain  
situations (but rarely all at once). I’d suggest that you could  
probably break that down into one main model with a number of has\_one/  
belongs\_to relationships. Armed with something like that you can  
create partials that are included as needed as well.

BTW, the scaffold _command_ was deprecated but the script/generate  
scaffold was not. If you’re creating a model/db-table from scratch  
then you can still do something like this:

script/generate scaffold MyClass attr1:type1 attr2:type2  
attr3:type3…

That will give you the forms that you’re looking for.

---

<div class="post-metadata">

**Author:** ![kellygreer1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/77aa72/32.png) [@kellygreer1](https://www.ruby-forum.com/u/kellygreer1)\
**Post date:** [April 21, 2008, 5:43pm UTC](https://www.ruby-forum.com/t/basic-rails-2-0-scaffold-and-commands-question/135107/7 "2008-04-21T17:43:24Z")

</div>

a few quick follow ups:

1. what is the proper way then to use the “script/generate scaffold”  
if you are backing in from the database side? or doing “database  
first”? maybe you are replacing a legacy web interface, but the  
database/data already exist.

2. what is the correct command to use if you would just like the  
Controller to be codegen’d (include all the standard methods) and not  
blank?

Kelly

---

<div class="post-metadata">

**Author:** ![kellygreer1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/77aa72/32.png) [@kellygreer1](https://www.ruby-forum.com/u/kellygreer1)\
**Post date:** [April 18, 2008, 12:48am UTC](https://www.ruby-forum.com/t/basic-rails-2-0-scaffold-and-commands-question/135107/8 "2008-04-18T00:48:40Z")

</div>

Ok. I have made it a little farther. If you delete the migrations  
related to the model it recreates the controller.  
But with scaffolding I now end up with code like this in my index  
view:

# Listing projects
\<% for project in @projects %\> \<% end %\>

|
| |
| \<%= link\_to 'Show', project %\> | \<%= link\_to 'Edit', edit\_project\_path(project) %\> | \<%= link\_to 'Destroy', project, :confirm =\> 'Are you sure?', :method =\> :delete %\> |

  
\<%= link\_to 'New project', new\_project\_path %\>

No fields in the output…  
So, when does Rails 2.0 do database introspection? or does it? where  
does it store this info?  
Is there a command to force rails to get its info from a pre-existing  
table?

Thanks,  
Kelly
