Re: scaffold_controller generator

Kendall Gifford
Tue, 14 Jun 2011 16:13:52 -0000

On Monday, June 13, 2011 6:36:10 PM UTC-6, madth3 wrote:
>
> 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


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.

--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To view this discussion on the web visit