scaffold_controller generator

36 views
Skip to first unread message

madth3

unread,
Jun 13, 2011, 8:36:10 PM6/13/11
to Ruby on Rails: Talk
Hi:

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?

Ruby 1.9.2
Rails 3.0.7

Kendall Gifford

unread,
Jun 14, 2011, 12:13:52 PM6/14/11
to rubyonra...@googlegroups.com

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.

Julio Aguilar

unread,
Jun 14, 2011, 2:57:16 PM6/14/11
to rubyonra...@googlegroups.com
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.

Thanks!

Reply all
Reply to author
Forward
0 new messages