Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed scaffold generator when started with only 1 parameter (closes #…

…2609) [self@mattmower.com]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2780 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 9bafd3537554d07b96b9edf049ff48ce262c30ac 1 parent bc73b83
@dhh dhh authored
View
2  railties/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed scaffold generator when started with only 1 parameter #2609 [self@mattmower.com]
+
* rake should run functional tests even if the unit tests have failures [Jim Weirich]
* Back off cleanpath to be symlink friendly. Closes #2533 [Nicholas Seckar]
View
9 railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb
@@ -46,9 +46,16 @@ class ScaffoldGenerator < Rails::Generator::NamedBase
def initialize(runtime_args, runtime_options = {})
super
- @controller_name = args.shift or (ActiveRecord::Base.pluralize_table_names ? @name.pluralize : @name)
+
+ if runtime_args.length > 1
+ @controller_name = runtime_args[1]
+ else
+ @controller_name = (ActiveRecord::Base.pluralize_table_names ? @name.pluralize : @name)
+ end
+
base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
@controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name)
+
if @controller_class_nesting.empty?
@controller_class_name = @controller_class_name_without_nesting
else
View
10 railties/test/rails_generator_test.rb
@@ -92,4 +92,14 @@ def test_named_generator_attributes_without_pluralized
g = Rails::Generator::Base.instance('working', %w(admin/foo bar baz))
assert_equal g.singular_name, g.table_name
end
+
+ def test_scaffold_controller_name
+ # Default behaviour is use the model name
+ g = Rails::Generator::Base.instance('scaffold', %w(Product))
+ assert_equal "Product", g.controller_name
+
+ # When we specify a controller name make sure it sticks!!
+ g = Rails::Generator::Base.instance('scaffold', %w(Product Admin))
+ assert_equal "Admin", g.controller_name
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.