我有以下嵌套资源:
resources :listings do
resources :offers do
member do
put "accept"
put "reject"
end
end
end
在我的列表/show.html.haml 中,我有
= button_to "Make Offer", new_listing_offer_path(@listing)
现在,当我单击按钮时,rails 会生成一个 POST 请求,因此会出现错误:
Started POST "/listings/2/offers/new" for 127.0.0.1
ActionController::RoutingError (No route matches "/listings/2/offers/new"):
如果我刷新(GET 请求),则页面正确显示。
我相信这种不正确的路由只有在我添加了两个额外的操作时才会发生:接受和拒绝,这恰好是 POST 操作。
这是 Rails 中的错误,还是我的错?我应该如何防止这个错误?
谢谢你。