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.

member actions in resource routing does not respect requirements for :id

#1365

  map.resources       :users,
                      :member => {:report => :get},
                      :requirements => {:id => /[+.a-z]+/}

/users/wiktor.schmidt/edit - works correctly

/users/wiktor.schmidt/report - gives route not found

Reported by Wiktor Schmidt · November 13th, 2008 @ 12:44 PM

State: duplicate
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Wiktor Schmidt
    Wiktor Schmidt

    How to fix it: in resources.rb:

    in method action_options_for lines:

    
              else                  default_options.merge(add_conditions_for(resource.conditions, method)).merge(resource.requirements)
    

    should look like

    
              else                  default_options.merge(add_conditions_for(resource.conditions, method)).merge(resource.requirements(require_id if this_is_a_member_action))
    

    I have no idea how make a "clean" this_is_a_member_action method...

    I quickly patched it by using a additional parameter for action_options_for:

    
          def action_options_for(action, resource, method = nil, member = false)
    
    
              else                  default_options.merge(add_conditions_for(resource.conditions, method)).merge(resource.requirements(require_id if member))
    

    and passing this parameter in map_member_actions:

    
          def map_member_actions(map, resource)
            resource.member_methods.each do |method, actions|
              actions.each do |action|
                action_options = action_options_for(action, resource, method, true)
    

    November 13th, 2008 @ 12:51 PM

  2. Wiktor Schmidt
  3. CancelProfileIsBroken