使用resources :posts, only: :show { get :detail }
我会得到这样的路线。
post_detail GET /posts/:post_id/detail(.:format) posts#detail
post GET /posts/:id(.:format) posts#show
我可以设置post_detail
的路由:id
而不是:post_id
吗?
我知道我可以按get '/posts/:id/detail', to: 'posts#detail', as: 'post_detail'
设置路线,但我想知道resources
是否有办法。
答案 0 :(得分:0)
resources :posts, only: :show do
member do
get 'detail'
end
end
或没有阻止:
resources :posts, only: :show do
get 'detail', on: :member
end
这会创建以下路线:
detail_post GET /posts/:id/detail(.:format) posts#detail
post GET /posts/:id(.:format) posts#show