[Rails] Pluralization in scaffold_generator.rb

Robby Russell robby at planetargon.com
Tue Mar 1 00:05:06 GMT 2005


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 at planetargon.com
* 503.351.4730  | blog.planetargon.com
* PHP/PostgreSQL Hosting & Development
* --- Now hosting Ruby on Rails Apps ---
****************************************/



More information about the Rails mailing list