轨道5.2.1
第3.8条
我正在尝试用嵌套的控制器构建restapi。我得到一个错误:
No route matches {:action=>"index", :controller=>"playlists/playlist_items", :format=>:json, :playlist=>60}
以下是我的路线.rb:
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
resources :playlists do
resources :playlist_items, controller: 'playlists/playlist_items'
end
resources :playlist_items
resources :artists
resources :tracks
end
rake routes
:
Prefix Verb URI Pattern Controller#Action
playlist_playlist_items GET /playlists/:playlist_id/playlist_items(.:format) playlists/playlist_items#index
POST /playlists/:playlist_id/playlist_items(.:format) playlists/playlist_items#create
playlist_playlist_item GET /playlists/:playlist_id/playlist_items/:id(.:format) playlists/playlist_items#show
PATCH /playlists/:playlist_id/playlist_items/:id(.:format) playlists/playlist_items#update
PUT /playlists/:playlist_id/playlist_items/:id(.:format) playlists/playlist_items#update
DELETE /playlists/:playlist_id/playlist_items/:id(.:format) playlists/playlist_items#destroy
... etc ...
以下是失败的测试:
describe Playlists::PlaylistItemsController do
describe "GET #index" do
before do
@playlist = create :playlist, { date: '2000-01-01' }
get :index, params: { playlist: @playlist.id, format: :json }
end
it "returns http success" do
expect(response).to have_http_status(:success)
end
end
end
错误抱怨没有路由匹配
{:action=>"index", :controller=>"playlists/playlist_items", :format=>:json, :playlist=>60}
耙道
完全匹配:
playlist_playlist_items GET /playlists/:playlist_id/playlist_items(.:format) playlists/playlist_items#index
我错过了什么?