我的route.rb文件中设置了以下路由:
resources :people do collection do get :search end end
当我对url:http://localhost:3000/people/search.json?term=stepeb采取行动时,
服务器报告它使用show操作进行响应,具有正确的术语参数,但也具有设置为“search”的id参数.
这个问题,正如我所看到的,是两个网址
展示网址将是:
/people/:id
我相信路由器在获得/ people / search之前匹配该路由
如果是这样,基于路由的路由将如何工作?他们都不会被演出动作所捕获吗?
耙路的相关部分如下:
search_people GET /people/search(.:format) {:action=>"search",:controller=>"people"} GET /people(.:format) {:action=>"index",:controller=>"people"} people POST /people(.:format) {:action=>"create",:controller=>"people"} new_person GET /people/new(.:format) {:action=>"new",:controller=>"people"} GET /people/:id(.:format) {:action=>"show",:controller=>"people"} PUT /people/:id(.:format) {:action=>"update",:controller=>"people"} person DELETE /people/:id(.:format) {:action=>"destroy",:controller=>"people"} edit_person GET /people/:id/edit(.:format) {:action=>"edit",:controller=>"people"}
解决方法
Doh,忘了这一个.原来我有一个重复的资源:人们在路线文件的顶部. Rails是第一个.似乎对我来说真的应该在那里检查重复的路由定义.