diff options
author | Pat George <pat.george@gmail.com> | 2008-06-04 15:13:50 -0400 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-06-27 16:35:26 +0100 |
commit | 4ddca325eeef46e640a225efb9b297260e1e8e7d (patch) | |
tree | aac70c659ec7c6e2b50ad1740708601edda8f651 /railties/lib/rails_generator/generators/components/scaffold | |
parent | 3c1e8ab0fecd5ee7f9328578016ef1e61214eeee (diff) | |
download | rails-4ddca325eeef46e640a225efb9b297260e1e8e7d.tar.gz rails-4ddca325eeef46e640a225efb9b297260e1e8e7d.tar.bz2 rails-4ddca325eeef46e640a225efb9b297260e1e8e7d.zip |
Warn and uses singularized ModelName if a plural ModelName is given to script/generate. Override with --force-plural. [#333 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'railties/lib/rails_generator/generators/components/scaffold')
-rw-r--r-- | railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb b/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb index e2902bf4b9..5fecfe0167 100644 --- a/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +++ b/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb @@ -1,5 +1,5 @@ class ScaffoldGenerator < Rails::Generator::NamedBase - default_options :skip_timestamps => false, :skip_migration => false + default_options :skip_timestamps => false, :skip_migration => false, :force_plural => false attr_reader :controller_name, :controller_class_path, @@ -16,6 +16,11 @@ class ScaffoldGenerator < Rails::Generator::NamedBase def initialize(runtime_args, runtime_options = {}) super + if @name == @name.pluralize && !options[:force_plural] + logger.warning "Plural version of the model detected, using singularized version. Override with --force-plural." + @name = @name.singularize + end + @controller_name = @name.pluralize base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name) @@ -81,6 +86,8 @@ class ScaffoldGenerator < Rails::Generator::NamedBase "Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v } opt.on("--skip-migration", "Don't generate a migration file for this model") { |v| options[:skip_migration] = v } + opt.on("--force-plural", + "Forces the generation of a plural ModelName") { |v| options[:force_plural] = v } end def scaffold_views |