I'm new to RoR and I apologize if this is a dumb question but I've
read the guides, searched the archives and found nothing.
If I generate a model object and then the scaffold_controller the
result is different than just running the scaffold generator (the
_form partial has no fields in the first case).
I did not expected this and I wanted to first create the models, tweak
them and then generate the scaffolds.
Did I made a mistake somewhere or is this by design?
You didn’t make any mistake.
It’s just that the scaffold_controller generator is perhaps not as smart as you’d like it to be. It doesn’t parse your migrations (or look at the current state of the database) in order to determine what attributes might exist on the associated model. As such, when creating your view templates, it can’t build-out any references to any specific fields.
However, the regular scaffold generator has the benefit of knowing the fields on the associated model because you provide them on the command line as “field:type” pairs:
$ rails g scaffold MyModel name:string age:int […]
If you really want your scaffolded view templates to include all your fields in them, then I suggest simply using the regular scaffold generator after having considered your data model enough to have a good, initial idea of what fields you want.
Ok, that makes sense.
I was fooled by the console messages saying that the “generate scaffold” command invokes the scaffold_controller generator
More than the fields themselves, I was hoping I could adjust the restrictions in the model before generating the controllers and views.