diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 19 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 13 |
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' |