Рельсы 5.2.1
RSpec 3.8
Я пытаюсь создать REST API с вложенными контроллерами. Я получаю сообщение об ошибке:
No route matches {:action=>"index", :controller=>"playlists/playlist_items", :format=>:json, :playlist=>60}
Вот мои маршруты.рб:
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}
но насколько я могу судить, эта строка из rake routes
точно соответствует:
playlist_playlist_items GET /playlists/:playlist_id/playlist_items(.:format) playlists/playlist_items#index
Чего мне не хватает?