This project is archived and is in readonly mode.

#6372 ✓committed
germaninthetown

Nested resources inside a shallow scope

Reported by germaninthetown | February 4th, 2011 @ 03:27 PM

Hello.

There is an issue with nested resources inside a shallow scope (kudos to Santiago Pastorino for pointing that out). For example if you specify this in your routes.rb:

scope '/hello' do
  shallow do
    resources :articles do
      resources :trackbacks
    end
  end
end

So when you run 'rake routes' you'll end up with

article_trackbacks GET    /articles/:article_id/trackbacks(.:format)     {:action=>"index", :controller=>"trackbacks"}
                      POST   /articles/:article_id/trackbacks(.:format)     {:action=>"create", :controller=>"trackbacks"}
new_article_trackback GET    /articles/:article_id/trackbacks/new(.:format) {:action=>"new", :controller=>"trackbacks"}
       edit_trackback GET    /trackbacks/:id/edit(.:format)                 {:action=>"edit", :controller=>"trackbacks"}
            trackback GET    /trackbacks/:id(.:format)                      {:action=>"show", :controller=>"trackbacks"}
                      PUT    /trackbacks/:id(.:format)                      {:action=>"update", :controller=>"trackbacks"}
                      DELETE /trackbacks/:id(.:format)                      {:action=>"destroy", :controller=>"trackbacks"}
             articles GET    /hello/articles(.:format)                      {:action=>"index", :controller=>"articles"}
                      POST   /hello/articles(.:format)                      {:action=>"create", :controller=>"articles"}
          new_article GET    /hello/articles/new(.:format)                  {:action=>"new", :controller=>"articles"}
         edit_article GET    /articles/:id/edit(.:format)                   {:action=>"edit", :controller=>"articles"}
              article GET    /articles/:id(.:format)                        {:action=>"show", :controller=>"articles"}
                      PUT    /articles/:id(.:format)                        {:action=>"update", :controller=>"articles"}
                      DELETE /articles/:id(.:format)                        {:action=>"destroy", :controller=>"articles"}

That is not all URI have a '/hello' prefix. I've attached a solution here which I hope is ok (also I added a test). Thanks.

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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Referenced by

Pages