Forum: Ruby on Rails script/generate scaffold pluralizes class names

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.
Jason F. (Guest)
on 2006-06-07 13:40
(Received via mailing list)
Hi everyone,

I'm a rails & ruby nuby, and this is my first post to the list.
Here's my environment in case it helps diagnose my problem:

Ruby version
1.8.4 (powerpc-darwin8.6.0)
RubyGems version
0.8.11
Rails version
1.1.2
Active Record version
1.14.2
Action Pack version
1.12.1
Action Web Service version
1.1.2
Action Mailer version
1.2.1
Active Support version
1.3.1

I did "rails myapp" and inserted "scaffold :foo" into the
controllers, which worked fine but I wanted to have the scaffold code
generated so I could see it and tweak it. So I did a "script/generate
scaffold foo" and it generated new views and controllers with
scaffolding in them, but now the controllers and views are all
pluralized: my user controller became users, my tag controller became
tags, etc. So looking at my file tree I wound up with two files names
tag_controller.rb & tags_controller.rb - inside the first line says
"TagsController" not "TagController" like when rails does it. Is this
a bug? Why would the generate script pluralize things just because I
want the scaffolding code inserted?

Is this a problem- will I wind up with other problems because my
controllers/views/who-knows-what-else are plural now? Every code
example I've read shows the controllers all being in the singular.

Any advice is appreciated!

Thanks,
-Jason
Mohit S. (Guest)
on 2006-06-07 15:14
(Received via mailing list)
Jason F. wrote:
> 1.1.2
>
> want the scaffolding code inserted?
>
> Is this a problem- will I wind up with other problems because my
> controllers/views/who-knows-what-else are plural now? Every code
> example I've read shows the controllers all being in the singular.
>
> Any advice is appreciated!
>
> Thanks,
> -Jason
>
Hi Jason,

That is normal behaviour.  When you "scaffold" an item, the URL will be
singular.  When you generate the scaffold code, it will be in the
plural.  In fact, you will find that both work fine.  For example, you
could do:
http://app/item  #this will use the default scaffold
or
http://app/items #this will use the generated code and changes made to
the generated code will show here

Hope this helps.  RoR has a seemingly esoteric naming convention, which
makes life a lot easier when you get used to it :)
Cheers
Mohit.
Brian H. (Guest)
on 2006-06-07 17:35
(Received via mailing list)
You can control this behavior by changing your generate command by
using the syntax

script/generate scaffold Model controller

e.g.,

script/generate scaffold Item item

script/generate scaffold Product admin
This topic is locked and can not be replied to.