From 0efedf2a30a12cdaa261556e3684c630690afe0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 30 Aug 2009 17:58:20 +0200 Subject: Ensure scaffold works properly even if plural name is given. [#3062] --- .../lib/generators/rails/resource/resource_generator.rb | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'railties/lib/generators/rails/resource') diff --git a/railties/lib/generators/rails/resource/resource_generator.rb b/railties/lib/generators/rails/resource/resource_generator.rb index 70babc0550..9abb8bbeaf 100644 --- a/railties/lib/generators/rails/resource/resource_generator.rb +++ b/railties/lib/generators/rails/resource/resource_generator.rb @@ -1,25 +1,19 @@ require 'generators/rails/model/model_generator' +require 'generators/resource_helpers' module Rails module Generators class ResourceGenerator < ModelGenerator #metagenerator + include ResourceHelpers + hook_for :resource_controller, :required => true do |base, controller| - base.invoke controller, [ base.name.pluralize, base.options[:actions] ] + base.invoke controller, [ base.controller_name, base.options[:actions] ] end class_option :actions, :type => :array, :banner => "ACTION ACTION", :default => [], :desc => "Actions for the resource controller" - class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller" - class_option :force_plural, :type => :boolean, :desc => "Forces the use of a plural ModelName" - - def initialize(*args) - super - if name == name.pluralize && !options[:force_plural] - say "Plural version of the model detected, using singularized version. Override with --force-plural." - name.replace name.singularize - end - end + class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller" def add_resource_route route "map.resource#{:s unless options[:singleton]} :#{pluralize?(file_name)}" -- cgit v1.2.3