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.

Error with rails 3 nested routes

#4854

The bug. I'm getting this error incorrectly:

No route matches {:action=>"destroy", :controller=>"admin/pledges"}

NOTE: This is triggered by a simple form_for:

<%= form_for @pledge, :url => admin_pledge_path do |f| %>

When I'm almost certain I've set everything up correctly, and to verify, when I do "rake routes" it shows me that this route indeed exists:

              GET    /admin/pledges(.:format)          {:action=>"index", :controller=>"admin/pledges"}
admin_pledges POST   /admin/pledges(.:format)          {:action=>"create", :controller=>"admin/pledges"}

new_admin_pledge GET /admin/pledges/new(.:format) {:action=>"new", :controller=>"admin/pledges"}

              GET    /admin/pledges/:id(.:format)      {:action=>"show", :controller=>"admin/pledges"}
              PUT    /admin/pledges/:id(.:format)      {:action=>"update", :controller=>"admin/pledges"}
 admin_pledge DELETE /admin/pledges/:id(.:format)      {:action=>"destroy", :controller=>"admin/pledges"}

edit_admin_pledge GET /admin/pledges/:id/edit(.:format) {:action=>"edit", :controller=>"admin/pledges"}

Here is the relevant part from my routes file:

namespace :admin do

resources :pledges

end

Reported by krschacht (at gmail) · June 14th, 2010 @ 02:06 AM

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Andrew White
    Andrew White

    You need to pass the id to the path helper:

    <%= form_for @pledge, :url => admin_pledge_path(@pledge) do |f| %>
    

    This should also work:

    <%= form_for [:admin, @pledge] do |f| %>
    

    June 14th, 2010 @ 01:07 PM

  2. krschacht (at gmail)
    krschacht (at gmail)

    Ack, sorry, you're right. That second example you gave solved eliminated the error.

    That error message really threw me, I was looking under the wrong rock with all that talk about routes. :)

    Thanks Andrew. I'll close out this ticket (if I can).

    June 14th, 2010 @ 04:08 PM

  3. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to invalid

    June 15th, 2010 @ 09:07 AM