This project is archived and is in readonly mode.

#4883 ✓duplicate
Alex Le

Routing error for restful resource under namespace

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

[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 %>


namespace :app do

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


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


I'm on ruby-1.8.7-p249

(edit 1: update formatting)

Comments and changes to this ticket

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=""></a>

People watching this ticket