diff options
-rw-r--r-- | railties/CHANGELOG | 2 | ||||
-rw-r--r-- | railties/Rakefile | 11 | ||||
-rw-r--r-- | railties/generators/scaffold/USAGE | 14 | ||||
-rw-r--r-- | railties/generators/scaffold/scaffold_generator.rb | 17 | ||||
-rw-r--r-- | railties/generators/scaffold/templates/controller.rb | 7 | ||||
-rw-r--r-- | railties/generators/scaffold/templates/view_show.rhtml | 2 |
6 files changed, 34 insertions, 19 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 008cf98c45..e5fb9ade29 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added the option to specify a controller name to "generate scaffold" and made the default controller name the plural form of the model. + * Added that rake clone_structure_to_test, db_structure_dump, and purge_test_database tasks now pick up the source database to use from RAILS_ENV instead of just forcing development #424 [Tobias Luetke] diff --git a/railties/Rakefile b/railties/Rakefile index 9719858f14..43723af8a2 100644 --- a/railties/Rakefile +++ b/railties/Rakefile @@ -39,6 +39,9 @@ task :fresh_gem_rails => [ :clean, :make_dir_structure, :initialize_file_stubs, desc "Generates a fresh Rails package without documentation (faster)" task :fresh_rails_without_docs => [ :clean, :make_dir_structure, :initialize_file_stubs, :copy_vendor_libraries, :copy_ties_content ] +desc "Generates a fresh Rails package without documentation (faster)" +task :fresh_rails_without_docs_using_links => [ :clean, :make_dir_structure, :initialize_file_stubs, :link_vendor_libraries, :copy_ties_content ] + desc "Packages the fresh Rails package with documentation" task :package => [ :clean, :fresh_rails ] do system %{cd ..; tar -czvf #{PKG_NAME}-#{PKG_VERSION}.tgz #{PKG_NAME}} @@ -89,6 +92,14 @@ task :copy_vendor_libraries do File.join(PKG_DESTINATION, 'vendor') end +desc "Link in all the Rails packages to vendor" +task :link_vendor_libraries do + return_dir = File.dirname(File.expand_path(__FILE__)) + cd File.join(PKG_DESTINATION, 'vendor') + VENDOR_LIBS.each { |dir| ln_s File.dirname(__FILE__) + "/../../#{dir}", "." } + cd return_dir +end + # Copy Ties Content ----------------------------------------------------------------------- diff --git a/railties/generators/scaffold/USAGE b/railties/generators/scaffold/USAGE index 338ba5aaf5..a8c9ed8967 100644 --- a/railties/generators/scaffold/USAGE +++ b/railties/generators/scaffold/USAGE @@ -2,12 +2,14 @@ GENERATOR scaffold - create a model and basic controller SYNOPSIS - generate scaffold ModelName [action ...] + generate scaffold ModelName [ControllerName] [action ...] DESCRIPTION The scaffold generator takes the name of the new model as the - first argument and an optional list of controller actions as the - subsequent arguments. Any actions with scaffolding code available + first argument, an optional controller name as the second, and + an optional list of controller actions as the subsequent arguments. + If the controller name is not specified, the plural form of the model + name will be used. Any actions with scaffolding code available will be generated in your controller; others will be left as stubs. The generated controller has the same code that "scaffold :model" @@ -15,11 +17,11 @@ DESCRIPTION your controller. EXAMPLE - ./script/generate scaffold Account debit credit + ./script/generate scaffold Account Bank debit credit This will generate the Account model with unit tests and fixtures, - the AccountController controller with actions, views, and tests for + the BankController controller with actions, views, and tests for index, list, show, new, create, edit, update, and destroy. Now create the accounts table in your database and browse to - http://localhost/account/ -- voila, you're on Rails! + http://localhost/bank/ -- voila, you're on Rails! 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 diff --git a/railties/generators/scaffold/templates/controller.rb b/railties/generators/scaffold/templates/controller.rb index 15ade4c49b..7ccb517bee 100644 --- a/railties/generators/scaffold/templates/controller.rb +++ b/railties/generators/scaffold/templates/controller.rb @@ -1,6 +1,4 @@ -class <%= class_name %>Controller < ApplicationController - layout 'scaffold' - +class <%= @controller_class_name %>Controller < ApplicationController <% unless suffix -%> def index list @@ -41,8 +39,7 @@ class <%= class_name %>Controller < ApplicationController def update @<%= singular_name %> = <%= class_name %>.find(@params['<%= singular_name %>']['id']) - @<%= singular_name %>.attributes = @params['<%= singular_name %>'] - if @<%= singular_name %>.save + if @<%= singular_name %>.update_attributes(@params['<%= singular_name %>']) flash['notice'] = '<%= class_name %> was successfully updated.' redirect_to :action => 'show<%= suffix %>', :id => @<%= singular_name %>.id else diff --git a/railties/generators/scaffold/templates/view_show.rhtml b/railties/generators/scaffold/templates/view_show.rhtml index 30a3242f14..ba8f3616dd 100644 --- a/railties/generators/scaffold/templates/view_show.rhtml +++ b/railties/generators/scaffold/templates/view_show.rhtml @@ -1,6 +1,6 @@ <%% for column in <%= class_name %>.content_columns %> <p> - <b><%%= column.human_name %>:</b> <%%= @<%= singular_name %>[column.name] %> + <b><%%= column.human_name %>:</b> <%%= @<%= singular_name %>.send(column.name) %> </p> <%% end %> |