Rails 中的路由问题!
这有效:http://127.0.0.1:3000/locations/1/statistics
但http://127.0.0.1:3000/locations/
不起作用。
我的路线如下所示:
resources :locations do
resources :statistics
end
如果我只是这样做,我只能工作 http://127.0.0.1:3000/locations/
resources locations
但是嵌套的路线不起作用!
我怎样才能让两者都工作?
非常感谢。
编辑耙子路线:
location_statistics GET /locations/:location_id/statistics(.:format) statistics#index
POST /locations/:location_id/statistics(.:format) statistics#create
new_location_statistic GET /locations/:location_id/statistics/new(.:format) statistics#new
edit_location_statistic GET /locations/:location_id/statistics/:id/edit(.:format) statistics#edit
location_statistic GET /locations/:location_id/statistics/:id(.:format) statistics#show
PUT /locations/:location_id/statistics/:id(.:format) statistics#update
DELETE /locations/:location_id/statistics/:id(.:format) statistics#destroy
locations GET /locations(.:format) locations#index
POST /locations(.:format) locations#create
new_location GET /locations/new(.:format) locations#new
edit_location GET /locations/:id/edit(.:format) locations#edit
location GET /locations/:id(.:format) locations#show
PUT /locations/:id(.:format) locations#update
DELETE /locations/:id(.:format) locations#destroy
home_index GET /home/index(.:format) home#index
about /about(.:format) home#about
contact /contact(.:format) home#contact
root / home#index
编辑 2条路线文件
match '/about/' => 'home#about'
match '/contact/' => 'home#contact'
resources :locations do
resources :statistics
end
get "home/index"
编辑3
我的实际错误:
Routing Error
No route matches {:controller=>"statistics", :location_id=>nil}
当我去http://127.0.0.1:3000/locations/