我有這樣的路線:在控制器的規格沒有路由匹配我的複雜路徑
resources :items, path: 'feed', only: [:index], defaults: { variant: :feed }
其嵌套在API和V1命名空間。 (request_source params來自Api命名空間)。
我想測試我的控制器規範中的索引動作。我想:
get :feed, community_id: community.id, :request_source=>"api"
不工作,也是如此:
get :index, community_id: community.id, :request_source=>"api", variant: 'feed'
說:
ActionController::RoutingError:
No route matches {:community_id=>"14", :request_source=>"api", :variant=>"feed", :controller=>"api/v1/items"}
------- --------編輯 -
我之所以要使用該變種將參數發送給控制器,是因爲我擁有所有這些路線:
resources :items, path: 'feed', only: [:index], defaults: { variant: 'feed' }
resources :items, path: 'popular', only: [:index], defaults: { variant: 'popular' }
然後,在上述ItemsController,我有一個過濾器「get_items」爲索引操作至極做之前:
def get_items
if params[:variant] == 'feed'
....
elsif params[:variant] == 'popular'
....
end
有什麼異常的回溯訪問該網站上不同的地方? –