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.

Routing error for restful resource under namespace

#4883

[I re-posted this ticket under 3.0RC]

There seems to be some issues with the routing for resources under a namespace. I have tried this on both Rails 3b3 and 3b4 and both failed:

View code:

<%= form_for @notebook, :url => toggle_app_notebook_path(@notebook), :remote => true do |form| %>
    <%= submit_tag 'Toggle' %>
<% end %>

routes.rb:

namespace :app do

resources :notebooks do
  member do
    get :toggle  # get always works
    post :toggle # Post returns 404
  end
end

end

rake routes generate this:

                                  GET    /app/notebooks/:id/toggle(.:format)                                      {:controller=>"app/notebooks", :action=>"toggle"}
              toggle_app_notebook POST   /app/notebooks/:id/toggle(.:format)                                      {:controller=>"app/notebooks", :action=>"toggle"}

While GET requests work as expected, the POST always failed with a 404 error:

No route matches "/app/notebooks/1/toggle

To get this route to work correctly, I have to declare another matcher outside the resources :notebooks but still under the namespace, and the URL would be recognized correctly:

namespace :app do

match 'notebooks/:id/toggle' => 'notebooks#toggle'
resources :notebooks do
  member do
    get :toggle  
    post :toggle
  end
end

end

I'm on ruby-1.8.7-p249

(edit 1: update formatting)

Reported by Alex Le · June 17th, 2010 @ 02:45 AM

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

Activity

  1. DHH
    DHH
    • State changed from new to duplicate

    June 17th, 2010 @ 04:01 PM