2016-05-30 9 views
1

フェニックスを見ると、レールがこれを実現する方法と同様のshallowルーティングに相当しますか?フェニックスフレームワークの浅いネストされたルート

これはあなたの代わりに/users/2/posts/1

などの/posts/1を参照できるようになる、

resources "/users", UserController do resources "/posts", PostController, shallow: true end

答えて

4

Phoenix.Router.resources/4ようには見えません:shallow OPTをサポートしていますが、これは仕事を得るでしょう:

resources "/users", UserController do 
    resources "/posts", PostController, only: [:index, :new, :create] 
end 
resources "/posts", PostController, except: [:index, :new, :create], as: :user_post 

mix phoenix.routesあなたのothのうちあなたが表示されます:

user_post_path GET  /users/:user_id/posts  YourApp.PostController :index 
user_post_path GET  /users/:user_id/posts/new YourApp.PostController :new 
user_post_path POST /users/:user_id/posts  YourApp.PostController :create 
user_post_path GET  /posts/:id/edit   YourApp.PostController :edit 
user_post_path GET  /posts/:id     YourApp.PostController :show 
user_post_path PATCH /posts/:id     YourApp.PostController :update 
       PUT  /posts/:id     YourApp.PostController :update 
user_post_path DELETE /posts/:id     YourApp.PostController :delete 
関連する問題