aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing/mapper.rb
diff options
context:
space:
mode:
authorMikel Lindsaar <raasdnil@gmail.com>2009-11-24 21:45:14 +1100
committerMikel Lindsaar <raasdnil@gmail.com>2009-11-24 21:45:14 +1100
commit5f2395041d1578433fa825ed5c6f26a201f2203d (patch)
tree3b78531ae77a2173ad0df1103543bdfea0b1f60f /actionpack/lib/action_dispatch/routing/mapper.rb
parent3a72923e27195983d37bdb39ef26b29cf03d3483 (diff)
parente62e6d409986cd5c99234689aa49e3162d7b3a59 (diff)
downloadrails-5f2395041d1578433fa825ed5c6f26a201f2203d.tar.gz
rails-5f2395041d1578433fa825ed5c6f26a201f2203d.tar.bz2
rails-5f2395041d1578433fa825ed5c6f26a201f2203d.zip
Merge branch 'master' of git://github.com/rails/rails into rails_master
Diffstat (limited to 'actionpack/lib/action_dispatch/routing/mapper.rb')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb32
1 files changed, 22 insertions, 10 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index ebfb4c9be2..cfe7425a61 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -52,30 +52,38 @@ module ActionDispatch
resource = resources.pop
+ plural = resource.to_s
+ singular = plural.singularize
+
if @scope[:scope_level] == :resources
- member do
- resources(resource, options, &block)
+ parent_resource = @scope[:scope_level_options][:name]
+ with_scope_level(:member) do
+ scope(":#{parent_resource}_id", :name_prefix => parent_resource) do
+ resources(resource, options, &block)
+ end
end
return self
end
- plural = resource.to_s
- singular = plural.singularize
+ if @scope[:options] && (prefix = @scope[:options][:name_prefix])
+ plural = "#{prefix}_#{plural}"
+ singular = "#{prefix}_#{singular}"
+ end
controller(resource) do
namespace(resource) do
- with_scope_level(:resources) do
+ with_scope_level(:resources, :name => singular) do
yield if block_given?
member do
- get "", :to => :show, :as => "#{singular}"
+ get "", :to => :show, :as => singular
put "", :to => :update
delete "", :to => :destroy
get "edit", :to => :edit, :as => "edit_#{singular}"
end
collection do
- get "", :to => :index, :as => "#{plural}"
+ get "", :to => :index, :as => plural
post "", :to => :create
get "new", :to => :new, :as => "new_#{singular}"
end
@@ -127,11 +135,13 @@ module ActionDispatch
end
private
- def with_scope_level(kind)
+ def with_scope_level(kind, options = {})
old, @scope[:scope_level] = @scope[:scope_level], kind
+ old_options, @scope[:scope_level_options] = @scope[:scope_level_options], options
yield
ensure
@scope[:scope_level] = old
+ @scope[:scope_level_options] = old_options
end
end
@@ -195,9 +205,9 @@ module ActionDispatch
@constraints.each { |constraint|
if constraint.respond_to?(:matches?) && !constraint.matches?(req)
- return Rack::Mount::Const::EXPECTATION_FAILED_RESPONSE
+ return [417, {}, []]
elsif constraint.respond_to?(:call) && !constraint.call(req)
- return Rack::Mount::Const::EXPECTATION_FAILED_RESPONSE
+ return [417, {}, []]
end
}
@@ -272,6 +282,8 @@ module ActionDispatch
constraints.reject! { |k, v| segment_keys.include?(k.to_s) }
conditions.merge!(constraints)
+ requirements[:controller] ||= Routing.controller_constraints
+
if via = options[:via]
via = Array(via).map { |m| m.to_s.upcase }
conditions[:request_method] = Regexp.union(*via)