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/newスコープが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 に答える