【发布时间】:2012-06-04 17:21:50
【问题描述】:
我的 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
我该怎么做?
谢谢
【问题讨论】:
-
您在更改路线后是否重新启动了您的应用程序?
-
是的,我在更改路由后重新启动了我的服务器。我正在使用 Rails 3.2。
-
你需要那个 :path => "/" 吗?
-
这就是问题所在,如果我删除
:path => "/"我的网址很长。我现在有http://localhost:3000/en/kevin29/collections但如果我删除:path => "/"我有这个:http://localhost:3000/en/users/kevin29/collections我想删除users前缀! -
您确定访问
/en/collectionstriggers collections#index 吗?我认为它必须触发 users#show,将字符串collections作为 id 传递给 params。
标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1 routes nested-resources