Permalink
Browse files

Router accepts member routes on resource. [#4624 state:resolved]

  • Loading branch information...
1 parent 83729e2 commit ac9f8e1b7bbbfa13ff75c86ef72fe6641ba26eb3 @rizwanreza rizwanreza committed with jeremy Jun 6, 2010
Showing with 27 additions and 5 deletions.
  1. +14 −5 actionpack/lib/action_dispatch/routing/mapper.rb
  2. +13 −0 actionpack/test/dispatch/routing_test.rb
@@ -622,13 +622,22 @@ def collection
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
@@ -28,6 +28,10 @@ def self.matches?(request)
post :reset
resource :info
+
+ member do
+ get :crush
+ end
end
match 'account/logout' => redirect("/logout"), :as => :logout_redirect
@@ -352,6 +356,15 @@ def test_session_info_nested_singleton_resource
end
end
+ def test_member_on_resource
+ with_test_routes do
+ get '/session/1/crush'
@pixeltrix
pixeltrix Jun 7, 2010 Member

This isn't right - a member action on a singleton resource shouldn't have an id. It should be /session/crush.

@josevalim
josevalim Jun 7, 2010 Member

In fact, I think it makes no sense to have :member at the resource level. It's redundant.

@pixeltrix
pixeltrix Jun 7, 2010 Member

That's the current behavior, however it depends on whether actions on a new resource are ever going to be added: https://rails.lighthouseapp.com/projects/8994/tickets/4328

@rizwanreza
rizwanreza Jun 7, 2010 Contributor

I agree that singleton resource shouldn't have an id or whatever, but if this is not the way, how does one add an action to a singleton resource when needed?

@pixeltrix
pixeltrix Jun 7, 2010 Member

Currently you just use get, etc. directly inside the block

+ 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'

0 comments on commit ac9f8e1

Please sign in to comment.