This project is archived and is in readonly mode.

#4854 ✓invalid
krschacht (at gmail)

Error with rails 3 nested routes

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

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

Comments and changes to this ticket

  • Andrew White

    Andrew White June 14th, 2010 @ 01:07 PM

    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| %>
    
  • krschacht (at gmail)

    krschacht (at gmail) June 14th, 2010 @ 04:08 PM

    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).

  • Rohit Arondekar

    Rohit Arondekar June 15th, 2010 @ 09:07 AM

    • State changed from “new” to “invalid”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages