【发布时间】:2012-08-18 08:33:59
【问题描述】:
我有这条路线:
resources :items, path: 'feed', only: [:index], defaults: { variant: :feed }
嵌套在 api 和 v1 命名空间中。 (request_source 参数来自 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
【问题讨论】:
-
异常的回溯是什么?
标签: ruby-on-rails rspec controller routes