Forum: Ruby on Rails Re: scaffolding generators and pluralization rules

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2006-01-23 16:02
(Received via mailing list)
Oops ;-p   Please forgive the previous, premature send.  To restart...

-----------------------------------------------------------

I've been working through the "Rolling with Ruby on Rails" tutorial and
have come up against something I'm hoping someone here can help me
understand.

In part one of the tutorial Curt steps the reader through the use of
'generate controller' and 'generate model'.  Way cool.  In part two, he
briefly introduces the new 'generate scaffold' but continues on using
what I thought was an equivalent approach that simply required more
steps on the programmer's part.  That is, I figured 'generate scaffold'
was a 'roll up' of existing functionality.  Unfortunately, my
investigation of 'generate scaffold' leaves me scratching my head.
Specifically...

The use of "generate controller" results in the creation of a
'recipe_controller.rb' file and a '..\views\recipe' folder.  The use of
'generate scaffold' creates 'recipes_controller' and '..\views\recipes'.
Class names within the controller are different too.

With 'convention' playing such an important role in Ruby and Rails, I've
got the feeling that I should understand what's going on here.  Can
anyone help?

Thanks,
Bill
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-01-23 16:09
(Received via mailing list)
Bill Walton wrote:
> With 'convention' playing such an important role in Ruby and Rails, I've
> got the feeling that I should understand what's going on here.  Can
> anyone help?

The scaffold generator just pluralises where the controller generator
doesn't.  That's all there is to it, really.  You can override the
pluralisation by saying script/generate scaffold ModelName ModelName
(that is, repeat the model name precisely).

It seems a little inconsistent, but I think I've got my head around the
logic behind why it's doing what it's doing.  Basically, when you
generate a controller on its own, the assumption is that you know what
it's for, and it may well not be tied to a specific model.  The
generator therefore can't assume that it's logical to pluralise the
name, because it doesn't know that your controller is going to be used
to control bunches of objects.

With the scaffolded code, on the other hand, the generator *does* know
that the controller is handling more than one object, so /pages/list
makes more sense than /page/list.

At least, that's how I see it.
This topic is locked and can not be replied to.