0

如何设置我的路线文件以创建以下路线:

/forums/1/posts           # GET  index
/forums/1/posts           # POST create
/forums/1/posts/new
# ... the other forum posts restful actions

/posts/1/votes            # POST create
/posts/1/votes/1/destroy

我试过这样:

resources :forums do
  resources :posts
end

resources :posts do
  resources :votes
end

这会创建冗余/posts/1/posts/newurl,而不是限定在forum.

我也试过:

resources :forums do
  resources :posts do
    resources :votes, only: [:create, :destroy], shallow: true
  end
end

但这会forums/1/posts/1/votes/create在我只想要的时候创建/posts/1/votes/create

基本上,我不想将资源嵌套在votes资源下forums

resources :posts do # would be nice to do resources :posts, none: true, do
  resources :votes
end

有任何想法吗?

4

1 回答 1

0

而不是:none => true你可以使用:only => []

resources :forums do
  resources :posts
end

resources :posts, :only => [] do
  resources :votes, :only => [:create, :destroy]
end
于 2013-06-07T20:09:15.420 回答