Fernando Brito
2010-Jun-23 17:52 UTC
Controller and Scaffold Controller generator - plural vs. singular
Hello, Why does: *$ rails g controller project* Generates *app/controllers/project_controller.rb* and *$ rails g scaffold_controller project* Generates *app/controllers/projects_controller.rb* and *app/views/projects/* ? With scaffold_controller there is even the following message at the end: "Plural version of the model detected, using singularized version. Override with --force-plural." Using singularized version? What? Which model is he talking about? There are no models in my (dummy) application. Thanks for the attention, -- Fernando Brito -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Robert Walker
2010-Jun-24 14:27 UTC
Re: Controller and Scaffold Controller generator - plural vs. singular
Fernando Brito wrote:> Why does: > > *$ rails g controller project* > Generates *app/controllers/project_controller.rb* > > and > > *$ rails g scaffold_controller project* > Generates *app/controllers/projects_controller.rb* and > *app/views/projects/*This is by design. Consider: $ rails g scaffold project name:string You will notice an output containing something like: invoke active_record create db/migrate/20100602201538_create_projects.rb create app/models/project.rb invoke test_unit create test/unit/project_test.rb create test/fixtures/projects.yml route resources :projects invoke scaffold_controller create app/controllers/projects_controller.rb Notice also the following line in the output: invoke scaffold_controller So, the scaffold_controller generator assumes the full MVC stack from model, through controller, to the views. In other words, running scaffold_controller assumes you already have a Project model and assumes the plural form that is the convention for controllers representing model objects. $ rails g controller project This makes no assumptions about anything and simply creates a controller file by appending _controller.rb to the name you supply to the generator. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Fernando Brito
2010-Jun-24 16:34 UTC
Re: Re: Controller and Scaffold Controller generator - plural vs. singular
Ah, thank you for your answer! :D I was not sure about Ruby on Rails convention of naming controllers in plural. :) -- Fernando Brito -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.