In rails 0.9.5, generators/scaffold_generator.rb, on line 11, it appears that the user-supplied class name is being pluralized, whereas other generators (e.g. controller) don''t pluralize the class name. Which behavior is right/best? Should scaffold_generator.rb be fixed or should the others be brought into conformity with it? Thanks, Carl
> In rails 0.9.5, generators/scaffold_generator.rb, on line 11, it > appears that the user-supplied class name is being pluralized, whereas > other generators (e.g. controller) don''t pluralize the class name. > Which behavior is right/best? Should scaffold_generator.rb be fixed > or should the others be brought into conformity with it?Pluralization only happens when you leave out the controller name. No other of the generators attempt to guess the name of the object being generated, so this is an isolated case. I''ve found that I most often want the controller name to be in plural, so that generate scaffold post will create a Post model and a PostsController. But as said, you can overwrite if you want to keep the singular, like "generate scaffold Account Account" that''ll give you an Account model and AccountController. -- David Heinemeier Hansson, http://www.basecamphq.com/ -- Web-based Project Management http://www.rubyonrails.org/ -- Web-application framework for Ruby http://macromates.com/ -- TextMate: Code and markup editor (OS X) http://www.loudthinking.com/ -- Broadcasting Brain
On Wed, 2005-02-02 at 17:12 +0100, David Heinemeier Hansson wrote:>> In rails 0.9.5, generators/scaffold_generator.rb, on line 11, it >> appears that the user-supplied class name is being pluralized, whereas >> other generators (e.g. controller) don''t pluralize the class name. >> Which behavior is right/best? Should scaffold_generator.rb be fixed >> or should the others be brought into conformity with it? > >Pluralization only happens when you leave out the controller name. No >other of the generators attempt to guess the name of the object being >generated, so this is an isolated case. > >I''ve found that I most often want the controller name to be in plural, >so that generate scaffold post will create a Post model and a >PostsController. But as said, you can overwrite if you want to keep the >singular, like "generate scaffold Account Account" that''ll give you an >Account model and AccountController.I ran: ./script/generate scaffold Employee Employee and it''s still looking for table ''Employees'' Is there a way that we can pass the database table that this references when calling generate? I have an existing db and would prefer to not have to rename all the tables, references, etc. I found this: class Mouse < ActiveRecord::Base def self.table_name() "mice" end end ..but was hoping that there was a way to have it not plural so that I don''t need to do this each time for all of the tables in the system. Cheers, -Robby -- /*************************************** * Robby Russell | Owner.Developer.Geek * PLANET ARGON | www.planetargon.com * Portland, OR | robby-/Lcn8Y7Ot69QmPsQ1CNsNQ@public.gmane.org * 503.351.4730 | blog.planetargon.com * PHP/PostgreSQL Hosting & Development * --- Now hosting Ruby on Rails Apps --- ****************************************/
On Mon, 28 Feb 2005 16:05:06 -0800, Robby Russell <robby-/Lcn8Y7Ot69QmPsQ1CNsNQ@public.gmane.org> wrote:> On Wed, 2005-02-02 at 17:12 +0100, David Heinemeier Hansson wrote: > >> In rails 0.9.5, generators/scaffold_generator.rb, on line 11, it > >> appears that the user-supplied class name is being pluralized, whereas > >> other generators (e.g. controller) don''t pluralize the class name. > >> Which behavior is right/best? Should scaffold_generator.rb be fixed > >> or should the others be brought into conformity with it? > > > >Pluralization only happens when you leave out the controller name. No > >other of the generators attempt to guess the name of the object being > >generated, so this is an isolated case. > > > >I''ve found that I most often want the controller name to be in plural, > >so that generate scaffold post will create a Post model and a > >PostsController. But as said, you can overwrite if you want to keep the > >singular, like "generate scaffold Account Account" that''ll give you an > >Account model and AccountController. > > I ran: > > ./script/generate scaffold Employee Employee > > and it''s still looking for table ''Employees'' > > Is there a way that we can pass the database table that this references > when calling generate? I have an existing db and would prefer to not > have to rename all the tables, references, etc. > > I found this: > > class Mouse < ActiveRecord::Base > def self.table_name() "mice" end > end > > ..but was hoping that there was a way to have it not plural so that I don''t need to do this each time for all of the tables in the system.What you''re looking for is: ActiveRecord::Base::pluralize_table_names = false. http://ar.rubyonrails.com/classes/ActiveRecord/Base.html#M000216> Cheers, > > -Robby > > -- > /*************************************** > * Robby Russell | Owner.Developer.Geek > * PLANET ARGON | www.planetargon.com > * Portland, OR | robby-/Lcn8Y7Ot69QmPsQ1CNsNQ@public.gmane.org > * 503.351.4730 | blog.planetargon.com > * PHP/PostgreSQL Hosting & Development > * --- Now hosting Ruby on Rails Apps --- > ****************************************/ > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Cheers Koz