我有一个带有对象,电影的应用程序,它没有使用某些标准的RESTful路由。我不想要新的'在任何地方领先的路线
问题是我有电影'使用嵌套资源'评论'
resources :movies do
resources :reviews
end
我想要这种路由方式:
get '/movies', to: "movies#index"
但是使用嵌套路线。这可能吗?我确定在这个网站的某个地方有这个答案,但我找不到它。
答案 0 :(得分:1)
您可以这样做:
resources :movies, :only => [:index] do
resources :reviews
end
哪个会给你:
movie_reviews GET /movies/:movie_id/reviews(.:format) reviews#index
POST /movies/:movie_id/reviews(.:format) reviews#create
new_movie_review GET /movies/:movie_id/reviews/new(.:format) reviews#new
edit_movie_review GET /movies/:movie_id/reviews/:id/edit(.:format) reviews#edit
movie_review GET /movies/:movie_id/reviews/:id(.:format) reviews#show
PATCH /movies/:movie_id/reviews/:id(.:format) reviews#update
PUT /movies/:movie_id/reviews/:id(.:format) reviews#update
DELETE /movies/:movie_id/reviews/:id(.:format) reviews#destroy
movies GET /movies(.:format) movies#index