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.

Rails 3 RC Routing: resource member routes lack defaults

#5431

When adding additional actions to a resource as shown in 2.9 of the routing guide (http://edgeguides.rubyonrails.org/routing.html), the action and route naming is not done by default. For example, placing the example code in a fresh app and running rake routes raises an error "missing :action" This can be fixed by changing the line to get 'preview', :action=>'preview', :as=>:preview.

Expected behavior:
1) The example code should parse
2) the action and route name should be inferred

Reported by Star Trader · August 24th, 2010 @ 01:47 AM

State: resolved
Milestone: 3.0.2
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. Santiago Pastorino
    Santiago Pastorino
    • Importance changed from to Low

    I can't reproduce this, can you provide more info, try doing a test case or upload an application?.
    Thanks.

    August 24th, 2010 @ 05:23 AM

  2. Andrew White
    Andrew White
    • Milestone cleared.
    • State changed from new to open
    • Assigned user set to Andrew White

    I think the problem is the guide shows the example using a string, whereas it should really be a symbol. I can't reproduce the missing action error but it is correct that the route isn't named.

    The action is added here, however I leaning towards thinking that it should removed and require the action to be specified. The problem with adding the action and name by default when specifying a custom action as a string is that you can add extra parameters in the path so you should really be adding all the options. e.g:

    resources :photos do
      get 'preview/:size', :on => :member
    end
    

    It wouldn't add too much overhead to add a regexp check on the name to see if it's compatible with adding it by default I guess, but the guide definitely needs updating.

    August 24th, 2010 @ 07:03 AM

  3. Andrew White
    Andrew White

    Okay, here's a patch to add a default name and action if the string is just alphanumeric.

    August 24th, 2010 @ 07:43 AM

  4. Santiago Pastorino
    Santiago Pastorino
    • Assigned user changed from Andrew White to José Valim

    I should be sleepy when i watched to this but i agree with Andrew, also +1 for the patch.
    Just wait for José resolution :).

    August 24th, 2010 @ 12:20 PM

  5. Repository
    Repository
    • State changed from open to resolved

    August 24th, 2010 @ 02:25 PM

  6. Repository
    Repository

    (from [8feb2856ea1e813bdefe64e9820cd1005aa5ad92]) When custom resource actions are specified using strings add the default name and action if the string is a valid ruby method name.

    [#5431 Rails 3 RC Routing: resource member routes lack defaults state:resolved]

    Signed-off-by: José Valim jose.valim@gmail.com
    http://github.com/rails/rails/commit/8feb2856ea1e813bdefe64e9820cd1...

    August 24th, 2010 @ 02:25 PM

  7. Repository
  8. Repository
    Repository

    (from [2fb0cbec024c5b51451deab7e390e2d4f712cf8f]) When custom resource actions are specified using strings add the default name and action if the string is a valid ruby method name.

    [#5431 Rails 3 RC Routing: resource member routes lack defaults state:resolved]

    Signed-off-by: José Valim jose.valim@gmail.com
    http://github.com/rails/rails/commit/2fb0cbec024c5b51451deab7e390e2...

    August 24th, 2010 @ 02:26 PM

  9. Jeremy Kemper