Skip to content
Browse files

dryed up resources; fixed small formatting issue in resources rdoc

Signed-off-by: Michael Koziarski <michael@koziarski.com>
  • Loading branch information...
1 parent 1db7c9c commit 14cf9a89919b72df301016e4596855c2112c6cef @jamesarosen jamesarosen committed with NZKoz Jun 13, 2008
Showing with 25 additions and 25 deletions.
  1. +25 −25 actionpack/lib/action_controller/resources.rb
View
50 actionpack/lib/action_controller/resources.rb
@@ -14,10 +14,10 @@ module ActionController
#
# === The Different Methods and their Usage
#
- # +GET+ Requests for a resource, no saving or editing of a resource should occur in a GET request
- # +POST+ Creation of resources
- # +PUT+ Editing of attributes on a resource
- # +DELETE+ Deletion of a resource
+ # [+GET+] Requests for a resource, no saving or editing of a resource should occur in a GET request
+ # [+POST+] Creation of resources
+ # [+PUT+] Editing of attributes on a resource
+ # [+DELETE+] Deletion of a resource
#
# === Examples
#
@@ -481,8 +481,7 @@ def map_collection_actions(map, resource)
resource.collection_methods.each do |method, actions|
actions.each do |action|
action_options = action_options_for(action, resource, method)
- map.named_route("#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.path}#{resource.action_separator}#{action}", action_options)
- map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.path}#{resource.action_separator}#{action}.:format", action_options)
+ map_named_routes(map, "#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.path}#{resource.action_separator}#{action}", action_options)
end
end
end
@@ -495,30 +494,25 @@ def map_default_collection_actions(map, resource)
index_route_name << "_index"
end
- map.named_route(index_route_name, resource.path, index_action_options)
- map.named_route("formatted_#{index_route_name}", "#{resource.path}.:format", index_action_options)
+ map_named_routes(map, index_route_name, resource.path, index_action_options)
create_action_options = action_options_for("create", resource)
- map.connect(resource.path, create_action_options)
- map.connect("#{resource.path}.:format", create_action_options)
+ map_unnamed_routes(map, resource.path, create_action_options)
end
def map_default_singleton_actions(map, resource)
create_action_options = action_options_for("create", resource)
- map.connect(resource.path, create_action_options)
- map.connect("#{resource.path}.:format", create_action_options)
+ map_unnamed_routes(map, resource.path, create_action_options)
end
def map_new_actions(map, resource)
resource.new_methods.each do |method, actions|
actions.each do |action|
action_options = action_options_for(action, resource, method)
if action == :new
- map.named_route("new_#{resource.name_prefix}#{resource.singular}", resource.new_path, action_options)
- map.named_route("formatted_new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}.:format", action_options)
+ map_named_routes(map, "new_#{resource.name_prefix}#{resource.singular}", resource.new_path, action_options)
else
- map.named_route("#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}#{resource.action_separator}#{action}", action_options)
- map.named_route("formatted_#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}#{resource.action_separator}#{action}.:format", action_options)
+ map_named_routes(map, "#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}#{resource.action_separator}#{action}", action_options)
end
end
end
@@ -532,22 +526,28 @@ def map_member_actions(map, resource)
action_path = resource.options[:path_names][action] if resource.options[:path_names].is_a?(Hash)
action_path ||= Base.resources_path_names[action] || action
- map.named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action_path}", action_options)
- map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action_path}.:format",action_options)
+ map_named_routes(map, "#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action_path}", action_options)
end
end
show_action_options = action_options_for("show", resource)
- map.named_route("#{resource.name_prefix}#{resource.singular}", resource.member_path, show_action_options)
- map.named_route("formatted_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}.:format", show_action_options)
+ map_named_routes(map, "#{resource.name_prefix}#{resource.singular}", resource.member_path, show_action_options)
update_action_options = action_options_for("update", resource)
- map.connect(resource.member_path, update_action_options)
- map.connect("#{resource.member_path}.:format", update_action_options)
+ map_unnamed_routes(map, resource.member_path, update_action_options)
destroy_action_options = action_options_for("destroy", resource)
- map.connect(resource.member_path, destroy_action_options)
- map.connect("#{resource.member_path}.:format", destroy_action_options)
+ map_unnamed_routes(map, resource.member_path, destroy_action_options)
+ end
+
+ def map_unnamed_routes(map, path_without_format, options)
+ map.connect(path_without_format, options)
+ map.connect("#{path_without_format}.:format", options)
+ end
+
+ def map_named_routes(map, name, path_without_format, options)
+ map.named_route(name, path_without_format, options)
+ map.named_route("formatted_#{name}", "#{path_without_format}.:format", options)
end
def add_conditions_for(conditions, method)
@@ -574,4 +574,4 @@ def action_options_for(action, resource, method = nil)
class ActionController::Routing::RouteSet::Mapper
include ActionController::Resources
-end
+end

0 comments on commit 14cf9a8

Please sign in to comment.
Something went wrong with that request. Please try again.