aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails_generator/generators/components/scaffold_resource
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/rails_generator/generators/components/scaffold_resource')
-rw-r--r--railties/lib/rails_generator/generators/components/scaffold_resource/USAGE2
-rw-r--r--railties/lib/rails_generator/generators/components/scaffold_resource/scaffold_resource_generator.rb45
2 files changed, 2 insertions, 45 deletions
diff --git a/railties/lib/rails_generator/generators/components/scaffold_resource/USAGE b/railties/lib/rails_generator/generators/components/scaffold_resource/USAGE
index 86d6ec31a9..9ccf4d9938 100644
--- a/railties/lib/rails_generator/generators/components/scaffold_resource/USAGE
+++ b/railties/lib/rails_generator/generators/components/scaffold_resource/USAGE
@@ -23,7 +23,7 @@ Description:
add "map.resources :posts" (notice the plural form) in the routes file. Then your new resource is accessible from
/posts.
-Example:
+Examples:
./script/generate scaffold_resource post # no attributes, view will be anemic
./script/generate scaffold_resource post title:string created_on:date body:text published:boolean
./script/generate scaffold_resource purchase order_id:integer created_at:datetime amount:decimal \ No newline at end of file
diff --git a/railties/lib/rails_generator/generators/components/scaffold_resource/scaffold_resource_generator.rb b/railties/lib/rails_generator/generators/components/scaffold_resource/scaffold_resource_generator.rb
index 7ea80ea5ac..ca6d997a9a 100644
--- a/railties/lib/rails_generator/generators/components/scaffold_resource/scaffold_resource_generator.rb
+++ b/railties/lib/rails_generator/generators/components/scaffold_resource/scaffold_resource_generator.rb
@@ -1,41 +1,4 @@
class ScaffoldResourceGenerator < Rails::Generator::NamedBase
- class ScaffoldAttribute
- attr_accessor :name, :type, :column
-
- def initialize(name, type)
- @name, @type = name, type.to_sym
- @column = ActiveRecord::ConnectionAdapters::Column.new(name, nil, @type)
- end
-
- def field_type
- @field_type ||= case type
- when :integer, :float, :decimal then :text_field
- when :datetime, :timestamp, :time then :datetime_select
- when :date then :date_select
- when :string then :text_field
- when :text then :text_area
- when :boolean then :check_box
- else
- :text_field
- end
- end
-
- def default
- @default ||= case type
- when :integer then 1
- when :float then 1.5
- when :decimal then "9.99"
- when :datetime, :timestamp, :time then Time.now.to_s(:db)
- when :date then Date.today.to_s(:db)
- when :string then "MyString"
- when :text then "MyText"
- when :boolean then false
- else
- ""
- end
- end
- end
-
attr_reader :controller_name,
:controller_class_path,
:controller_file_path,
@@ -121,7 +84,7 @@ class ScaffoldResourceGenerator < Rails::Generator::NamedBase
protected
# Override with your own usage banner.
def banner
- "Usage: #{$0} scaffold_resource ModelName"
+ "Usage: #{$0} scaffold_resource ModelName [field:type, field:type]"
end
def scaffold_views
@@ -131,10 +94,4 @@ class ScaffoldResourceGenerator < Rails::Generator::NamedBase
def model_name
class_name.demodulize
end
-
- def attributes
- @attributes ||= args.collect do |attribute|
- ScaffoldAttribute.new(*attribute.split(":"))
- end
- end
end