就我而言,我已经与完全古怪的 routes.rb 行为作斗争。我试图在我的 Rails 应用程序中实现 Carmen gem。我跟着这个教程。我只想要两个从属选择框,其中第一个是国家,第二个是区域(在本例中为子区域)。我花了将近两个小时找出为什么它不起作用。最后,解决方案非常简单——只需在 routes.rb 中切换两行即可。现在我的问题。我可以请任何人解释为什么在第一种情况下是来自服务器错误的响应以及为什么我的 rails 应用程序试图在显示操作时发送请求?我真的不明白。谢谢你。
错误:
Routes.rb
resources :orders
get '/orders/subregion_options' => 'orders#subregion_options'
Server output
Started GET "/orders/subregion_options?parent_region=US" for 127.0.0.1 at 2012-08-13 23:18:35 -0700
Processing by OrdersController#show as HTML
Parameters: {"parent_region"=>"US", "id"=>"subregion_options"}
Order Load (1.3ms) SELECT "orders".* FROM "orders" WHERE "orders"."id" = $1 LIMIT 1 [["id", "subregion_options"]]
Completed 500 Internal Server Error in 3ms
ActiveRecord::RecordNotFound (Couldn't find Order with id=subregion_options):
app/controllers/orders_controller.rb:26:in `show'
正确行为:
Routes.rb
get '/orders/subregion_options' => 'orders#subregion_options'
resources :orders
Server output
Started GET "/orders/subregion_options?parent_region=US" for 127.0.0.1 at 2012-08-13 23:20:10 -0700
Processing by OrdersController#subregion_options as HTML
Parameters: {"parent_region"=>"US"}
Rendered orders/_subregion_select.html.erb (3.0ms)
Completed 200 OK in 5ms (Views: 4.6ms | ActiveRecord: 0.0ms)