Is there a proper pluralization practice I should be using when generating controlers and models? Should it be: script/generate controller Widget script/generate model Widget or plural: script/generate controller Widgets script/generate model Widgets or maybe controllers should always be plural and the model singular? Also, does capitalizing the first letter matter? Thanks, DAN -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Matt Sir
2007-Jun-24 19:39 UTC
Re: Newbie: Still confused on pluralizing controllers and mo
Hi! I''m no expert either, but when you generate you do it single. It does not matter if the first word is capital but you have to do multiple words camelcased. So script/generate module LotsOfWiget will make lots_of_wigets in your database Whatever you type in to the name for generate model name, name.pluralize.underscore is called so you can test it out in the console if you want to see what will get created! As far as controllers plural or singular I guess it doesn''t matter, but I think it makes more sense if a controller is singular since there is only one item. generating a controller will not get changed into a plural object I believe. the function underscore gets called on the name. Models should always be singular. Matt DAN wrote:> Is there a proper pluralization practice I should be using when > generating controlers and models? > > Should it be: > > script/generate controller Widget > script/generate model Widget > > or plural: > > script/generate controller Widgets > script/generate model Widgets > > or maybe controllers should always be plural and the model singular? > > Also, does capitalizing the first letter matter? > > Thanks, > DAN-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Michael Glaesemann
2007-Jun-29 01:38 UTC
Re: Newbie: Still confused on pluralizing controllers and mo
On Jun 24, 2007, at 14:39 , Matt Sir wrote:> As far as controllers plural or singular I guess it doesn''t matter, > but > I think it makes more sense if a controller is singular since there is > only one item. generating a controller will not get changed into a > plural object I believe. the function underscore gets called on the > name.I believe current recommended practice is to have plural controllers. For example, script/generate scaffold widget creates app/models/widget.rb and app/controllers/ widgets_controller.rb What does a WidgetsController do? It controls all widgets (note the plural). Michael Glaesemann grzm seespotcode net --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jean Nibee
2007-Jun-29 03:31 UTC
Re: Newbie: Still confused on pluralizing controllers and mo
> > I believe current recommended practice is to have plural controllers. > For example, > > script/generate scaffold widget > > creates app/models/widget.rb and app/controllers/ > widgets_controller.rb What does a WidgetsController do? It controls > all widgets (note the plural). > > Michael Glaesemann > grzm seespotcode netHere''s how I see it (one mans opinion) DB Table => Plural (products, people, invoices.. etc) Model => Singular (product, person, invoice.. etc) Controler => Doesn''t matter. So long as you understand the connection. store (controller managing products) user_admin (controller managing the people in your site) accounting (controller for invoices) Yes granted you could pluralize your controllers, but I think since a controller wraps functionality around your models (its'' the CRUD after all) and isn''t just a series / list of models itself; making the name descriptive makes more sense to me. Also, don''t forget, eventually once you get past "scaffolding-only" controller code your controller will be managing business logic around your model and not just the state of a model itself. So it will grow beyond the definition of "People, Invoices or Products" as a description. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jean Nibee
2007-Jun-29 03:34 UTC
Re: Newbie: Still confused on pluralizing controllers and mo
Jean Nibee wrote:> > Here''s how I see it (one mans opinion) > > DB Table => Plural (products, people, invoices.. etc) > Model => Singular (product, person, invoice.. etc) > Controler => Doesn''t matter. So long as you understand the connection. > store (controller managing products) > user_admin (controller managing the people in your site) > accounting (controller for invoices) > > Yes granted you could pluralize your controllers, but I think since a > controller wraps functionality around your models (its'' the CRUD after > all) and isn''t just a series / list of models itself; making the name > descriptive makes more sense to me. > > Also, don''t forget, eventually once you get past "scaffolding-only" > controller code your controller will be managing business logic around > your model and not just the state of a model itself. So it will grow > beyond the definition of "People, Invoices or Products" as a > description.I apologise I hit enter too quick and there''s no edit on this board.... Paragraph TWO should not have "(its'' the CRUD after all)" I meant to correct that error and delete it before submitting. Sorry, -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jim Tobin
2007-Jul-13 21:23 UTC
Re: Newbie: Still confused on pluralizing controllers and mo
I think I got all twisted around with camels and pluralizes, such that I''m getting load errors. This is just a small identity attribute that I want to be able to add to, so having auto-generated scaffold is okay for now... once I get past load errors! /app/models/project_type.rb <== should that be ProjectType.rb, projectType.rb or as is? class ProjectType < ActiveRecord::Base end /db/migrate/008_create_project_types.rb <== created using generate model projectTypes IIRC class CreateProjectTypes < ActiveRecord::Migration def self.up create_table :project_types do |t| t.column "name", :string end end /app/controllers/project_types_controller.rb class ProjectTypesController < ApplicationController scaffold :project_types end all this (begun using script/generate commands, then for better or worse edited by me to try getting around load errors) results in: LoadError in Project typesController#index app/models/project_type.rb to define ProjectType On Jun 28, 2007, at 8:31 PM, Jean Nibee wrote:> >> >> I believe current recommended practice is to have plural controllers. >> For example, >> >> script/generate scaffold widget >> >> creates app/models/widget.rb and app/controllers/ >> widgets_controller.rb What does a WidgetsController do? It controls >> all widgets (note the plural). >> >> Michael Glaesemann >> grzm seespotcode net > > Here''s how I see it (one mans opinion) > > DB Table => Plural (products, people, invoices.. etc) > Model => Singular (product, person, invoice.. etc) > Controler => Doesn''t matter. So long as you understand the connection. > store (controller managing products) > user_admin (controller managing the people in your site) > accounting (controller for invoices) > > Yes granted you could pluralize your controllers, but I think since a > controller wraps functionality around your models (its'' the CRUD after > all) and isn''t just a series / list of models itself; making the name > descriptive makes more sense to me. > > Also, don''t forget, eventually once you get past "scaffolding-only" > controller code your controller will be managing business logic around > your model and not just the state of a model itself. So it will grow > beyond the definition of "People, Invoices or Products" as a > description. > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Matthew Rudy
2007-Jul-14 13:56 UTC
Re: Newbie: Still confused on pluralizing controllers and mo
All the code you''ve given is correct, unless you have "ActiveRecord::Base.pluralize_table_names = false" in you environment.rb file. if you''re getting a load failure, I image there''s a different problem. Go into ruby script/console and type "ProjectType" hopefully it''ll give you a more verbose error, could be that ActiveRecord::Base isn''t working properly.> /app/models/project_type.rb <== should that be ProjectType.rb, > projectType.rb or as is? > class ProjectType < ActiveRecord::Base > end > > /db/migrate/008_create_project_types.rb <== created using generate > model projectTypes IIRC > class CreateProjectTypes < ActiveRecord::Migration > def self.up > create_table :project_types do |t| > t.column "name", :string > end > end > > /app/controllers/project_types_controller.rb > class ProjectTypesController < ApplicationController > scaffold :project_types > end > > all this (begun using script/generate commands, then for better or > worse edited by me to try getting around load errors) results in: > LoadError in Project typesController#index > > app/models/project_type.rb to define ProjectType-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---