资源可用输出父资源轨道3.2

时间:2012-06-04 17:21:50

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1 routes nested-resources

我在我的routes.rb中有这个。

resources :users, :path => "/", :only => [:show] do
  resources :collections, :controller => 'users/collections'
end

为什么我可以从以下位置访问馆藏资源:

http://localhost:3000/en/collections

如果这可以在内部用户中使用?

我希望collection resource仅在内部启用:

http://localhost:3000/en/users/collections

这是我的路线:

user_collections GET    (/:locale)/:user_id/collections(.:format)          users/collections#index
                         POST   (/:locale)/:user_id/collections(.:format)          users/collections#create
     new_user_collection GET    (/:locale)/:user_id/collections/new(.:format)      users/collections#new
    edit_user_collection GET    (/:locale)/:user_id/collections/:id/edit(.:format) users/collections#edit
         user_collection GET    (/:locale)/:user_id/collections/:id(.:format)      users/collections#show
                         PUT    (/:locale)/:user_id/collections/:id(.:format)      users/collections#update
                         DELETE (/:locale)/:user_id/collections/:id(.:format)      users/collections#destroy

我该怎么做?

谢谢

1 个答案:

答案 0 :(得分:0)

试试这个:

resources :users, :only => [:show] do
  resources :collections, :controller => 'users/collections'
end