From 52251baae48cf25ea06106569af3d04c76841210 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 13 Jan 2005 15:49:26 +0000 Subject: Added the option to specify a controller name to "generate scaffold" and made the default controller name the plural form of the model. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@404 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/generators/scaffold/scaffold_generator.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'railties/generators/scaffold/scaffold_generator.rb') diff --git a/railties/generators/scaffold/scaffold_generator.rb b/railties/generators/scaffold/scaffold_generator.rb index 55bb835bb7..00dd27c5ed 100644 --- a/railties/generators/scaffold/scaffold_generator.rb +++ b/railties/generators/scaffold/scaffold_generator.rb @@ -8,14 +8,17 @@ class ScaffoldGenerator < Rails::Generator::Base # Fixtures. template "fixtures.yml", "test/fixtures/#{table_name}.yml" + @controller_class_name = args.empty? ? Inflector.pluralize(class_name) : args.shift.sub(/^[a-z]?/) { |m| m.capitalize } + controller_name = Inflector.underscore(@controller_class_name) + # Controller class, functional test, helper, and views. - template "controller.rb", "app/controllers/#{file_name}_controller.rb" - template "functional_test.rb", "test/functional/#{file_name}_controller_test.rb" - template "controller/helper.rb", "app/helpers/#{file_name}_helper.rb" + template "controller.rb", "app/controllers/#{controller_name}_controller.rb" + template "functional_test.rb", "test/functional/#{controller_name}_controller_test.rb" + template "controller/helper.rb", "app/helpers/#{controller_name}_helper.rb" # Layout and stylesheet. - unless File.file?("app/views/layouts/scaffold.rhtml") - template "layout.rhtml", "app/views/layouts/scaffold.rhtml" + unless File.file?("app/views/layouts/#{controller_name}.rhtml") + template "layout.rhtml", "app/views/layouts/#{controller_name}.rhtml" end unless File.file?("public/stylesheets/scaffold.css") template "style.css", "public/stylesheets/scaffold.css" @@ -23,13 +26,13 @@ class ScaffoldGenerator < Rails::Generator::Base # Scaffolded views. scaffold_views.each do |action| - template "view_#{action}.rhtml", "app/views/#{file_name}/#{action}.rhtml" + template "view_#{action}.rhtml", "app/views/#{controller_name}/#{action}.rhtml" end # Unscaffolded views. unscaffolded_actions.each do |action| template "controller/view.rhtml", - "app/views/#{file_name}/#{action}.rhtml", + "app/views/#{controller_name}/#{action}.rhtml", binding end end -- cgit v1.2.3