aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRizwan Reza <rizwanreza@gmail.com>2010-06-06 14:00:09 +0430
committerJeremy Kemper <jeremy@bitsweat.net>2010-06-06 21:27:52 -0400
commitac9f8e1b7bbbfa13ff75c86ef72fe6641ba26eb3 (patch)
tree760f73fb814fcf3b40977edb2b53174b7b07862f
parent83729e2fe36a0a629c2a5a52a7e2970287d57036 (diff)
downloadrails-ac9f8e1b7bbbfa13ff75c86ef72fe6641ba26eb3.tar.gz
rails-ac9f8e1b7bbbfa13ff75c86ef72fe6641ba26eb3.tar.bz2
rails-ac9f8e1b7bbbfa13ff75c86ef72fe6641ba26eb3.zip
Router accepts member routes on resource. [#4624 state:resolved]
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb19
-rw-r--r--actionpack/test/dispatch/routing_test.rb13
2 files changed, 27 insertions, 5 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 8a8d21c434..63c553dd07 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -622,13 +622,22 @@ module ActionDispatch
end
def member
- unless @scope[:scope_level] == :resources
- raise ArgumentError, "can't use member outside resources scope"
+ unless [:resources, :resource].include?(@scope[:scope_level])
+ raise ArgumentError, "You can't use member action outside resources and resource scope."
end
- with_scope_level(:member) do
- scope(':id', :name_prefix => parent_resource.member_name, :as => "") do
- yield
+ case @scope[:scope_level]
+ when :resources
+ with_scope_level(:member) do
+ scope(':id', :name_prefix => parent_resource.member_name, :as => "") do
+ yield
+ end
+ end
+ when :resource
+ with_scope_level(:member) do
+ scope(':id', :as => "") do
+ yield
+ end
end
end
end
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 180889ddf2..b2b8aca9b2 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -28,6 +28,10 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
post :reset
resource :info
+
+ member do
+ get :crush
+ end
end
match 'account/logout' => redirect("/logout"), :as => :logout_redirect
@@ -352,6 +356,15 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
+ def test_member_on_resource
+ with_test_routes do
+ get '/session/1/crush'
+ assert_equal 'sessions#crush', @response.body
+
+ assert_equal '/session/1/crush', crush_session_path(1)
+ end
+ end
+
def test_redirect_modulo
with_test_routes do
get '/account/modulo/name'