Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

In the new router, "can't use member outside resources scope"

#3951

In Rails 2.3.5 it was possible to have a member on a RESTful resource.

When trying this in Rails 3.0.0.beta:

resources :users do

resource :open_id do
  member do
    get :remove
  end
end

end

It fails with:

ArgumentError: can't use member outside resources scope

The same occurs when using collection inside resource.

Is this on purpose, and if so, is there another solution?

Reported by Lasse Bunk · February 13th, 2010 @ 07:46 PM

State: invalid
Milestone: none
Assigned to: Aaron Patterson Aaron Patterson
Importance: Low

Activity

  1. Balazs Nagy
    Balazs Nagy

    Why do you want to add a member to a single resource? Members expect that you want to reference of a resource by ID.

    You can create extra routes for a resource like this:

    resource :open_id do
      get :remove
    end
    

    February 13th, 2010 @ 08:08 PM

  2. Lasse Bunk
    Lasse Bunk

    Sorry – my bad. I'll be using get :remove instead. Thanks. Out of curiosity, could you tell me what would've been right one to use instead of using a member on Rails < 3.0.0?

    February 13th, 2010 @ 09:01 PM

  3. Lasse Bunk
    Lasse Bunk

    Another thing is that get :remove on a singular resource (resource :open_id) doesn't create the remove_open_id_path route helper that is created when using

    member do
      get :remove
    end
    

    on plural resources (resources :open_id). Is that a bug? I can create the helper by specifying :as => :open_id (why does it have to be :open_id?)

    February 13th, 2010 @ 09:50 PM

  4. José Valim
    José Valim
    • Assigned user set to josh

    February 16th, 2010 @ 09:47 PM

  5. josh
    josh
    • State changed from new to invalid

    Right, you just need

    resource :open_id do
      get :remove
    end
    

    Think of the inside of "resource" (singular) as already scoped with member.

    February 19th, 2010 @ 03:47 PM

  6. Lasse Bunk
    Lasse Bunk

    Ok – I get that... nicely done :)
    The fact that it doesn't create a remove_open_id helper – is that a bug?

    February 19th, 2010 @ 04:27 PM

  7. josh
    josh

    Sounds like it. Could you post a failing test.

    February 19th, 2010 @ 07:00 PM

  8. Claudio Amoedo
    Claudio Amoedo

    I have the same issue with resource path helpers

    February 24th, 2010 @ 11:18 PM

  9. valerie82
    valerie82
    • Assigned user changed from josh to Aaron Patterson

    nice to read write my essay

    June 7th, 2010 @ 10:19 PM