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:
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?
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.
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!
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:
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?