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.

Nested resources inside a shallow scope

#6372

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.

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

State: committed
Milestone: none
Assigned to: Santiago Pastorino Santiago Pastorino
Importance: none

Activity

  1. Repository
    Repository
    • State changed from new to committed

    (from [adbae9aab8a439a824cf1612febb5918d0f4cf87]) fixed bug with nested resources within shallow scope

    [#6372 state:committed]

    Signed-off-by: Santiago Pastorino santiago@wyeworks.com
    https://github.com/rails/rails/commit/adbae9aab8a439a824cf1612febb5...

    February 4th, 2011 @ 08:41 PM