Permalink
Browse files

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
  • Loading branch information...
1 parent 9c09f81 commit 52251baae48cf25ea06106569af3d04c76841210 @dhh dhh committed Jan 13, 2005
View
2 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]
View
11 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 -----------------------------------------------------------------------
View
14 railties/generators/scaffold/USAGE
@@ -2,24 +2,26 @@ 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"
uses, so it's easy to migrate when you want to start customizing
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!
View
17 railties/generators/scaffold/scaffold_generator.rb
@@ -8,28 +8,31 @@ def generate
# 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"
end
# 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
View
7 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 @@ def edit<%= suffix %>
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
View
2 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 %>

0 comments on commit 52251ba

Please sign in to comment.