如何设置我的路线文件以创建以下路线:
/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/new
url,而不是限定在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
有任何想法吗?