mirror of
https://github.com/github/rails.git
synced 2026-01-30 16:58:15 -05:00
resource and scaffold_resource generators add a restful route to config/routes.rb
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5379 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* resource and scaffold_resource generators add a restful route to config/routes.rb [Jeremy Kemper]
|
||||
|
||||
* Revert environment changes for autoload_paths. [Koz]
|
||||
|
||||
* Update to latest Prototype, which doesn't serialize disabled form elements, adds clone() to arrays, empty/non-string Element.update() and adds a fixes excessive error reporting in WebKit beta versions [Thomas Fuchs]
|
||||
|
||||
@@ -83,6 +83,12 @@ module Rails
|
||||
"%.#{padding}d" % next_migration_number
|
||||
end
|
||||
|
||||
def gsub_file(relative_destination, regexp, *args, &block)
|
||||
path = destination_path(relative_destination)
|
||||
content = File.read(path).gsub(regexp, *args, &block)
|
||||
File.open(path, 'wb') { |file| file.write(content) }
|
||||
end
|
||||
|
||||
private
|
||||
# Ask the user interactively whether to force collision.
|
||||
def force_file_collision?(destination)
|
||||
@@ -316,6 +322,16 @@ module Rails
|
||||
template(relative_source, "#{relative_destination}/#{next_migration_string}_#{migration_file_name}.rb", template_options)
|
||||
end
|
||||
|
||||
def route_resources(*resources)
|
||||
resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
|
||||
sentinel = 'ActionController::Routing::Routes.draw do |map|'
|
||||
|
||||
logger.route "map.resources #{resource_list}"
|
||||
gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
|
||||
"#{match}\n map.resources #{resource_list}\n"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Raise a usage error with an informative WordNet suggestion.
|
||||
# Thanks to Florian Gross (flgr).
|
||||
@@ -438,6 +454,13 @@ end_message
|
||||
file(relative_source, file_path, template_options)
|
||||
end
|
||||
end
|
||||
|
||||
def route_resources(*resources)
|
||||
resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
|
||||
look_for = "\n map.resources #{resource_list}\n"
|
||||
logger.route "map.resources #{resource_list}"
|
||||
gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -475,6 +498,11 @@ end_message
|
||||
migration_directory relative_destination
|
||||
logger.migration_template file_name
|
||||
end
|
||||
|
||||
def route_resources(*resources)
|
||||
resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
|
||||
logger.route "map.resources #{resource_list}"
|
||||
end
|
||||
end
|
||||
|
||||
# Update generator's action manifest.
|
||||
|
||||
@@ -26,7 +26,7 @@ class ResourceGenerator < Rails::Generator::NamedBase
|
||||
end
|
||||
|
||||
def manifest
|
||||
recorded_session = record do |m|
|
||||
record do |m|
|
||||
# Check for class naming collisions.
|
||||
m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
|
||||
m.class_collisions(class_path, "#{class_name}")
|
||||
@@ -60,18 +60,9 @@ class ResourceGenerator < Rails::Generator::NamedBase
|
||||
:migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
|
||||
)
|
||||
end
|
||||
|
||||
m.route_resources controller_file_name
|
||||
end
|
||||
|
||||
puts
|
||||
puts ("-" * 70)
|
||||
puts "Don't forget the restful route in config/routes.rb"
|
||||
puts
|
||||
puts " map.resources :#{controller_file_name}"
|
||||
puts
|
||||
puts ("-" * 70)
|
||||
puts
|
||||
|
||||
recorded_session
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
@@ -26,7 +26,7 @@ class ScaffoldResourceGenerator < Rails::Generator::NamedBase
|
||||
end
|
||||
|
||||
def manifest
|
||||
recorded_session = record do |m|
|
||||
record do |m|
|
||||
# Check for class naming collisions.
|
||||
m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
|
||||
m.class_collisions(class_path, "#{class_name}")
|
||||
@@ -67,18 +67,9 @@ class ScaffoldResourceGenerator < Rails::Generator::NamedBase
|
||||
:migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
|
||||
)
|
||||
end
|
||||
|
||||
m.route_resources controller_file_name
|
||||
end
|
||||
|
||||
puts
|
||||
puts ("-" * 70)
|
||||
puts "Don't forget the restful route in config/routes.rb"
|
||||
puts
|
||||
puts " map.resources :#{controller_file_name}"
|
||||
puts
|
||||
puts ("-" * 70)
|
||||
puts
|
||||
|
||||
recorded_session
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
Reference in New Issue
Block a user