擁有2個模型customer和comm_log。它們的關聯如下:如何在rails 3.1中的link_to中構造刪除路由?
resources :customers do
comm_logs
end
在comm_logs控制器中銷燬的rspec代碼沒有任何錯誤地傳遞。 lambda模塊驗證成功刪除後,通訊記錄數減1。控制器中的一切看起來都是正確
耙路線的輸出是:
new_customer_comm_log GET /customers/:customer_id/comm_logs/new(.:format) {:action=>"new", :controller=>"comm_logs"}
edit_customer_comm_log GET /customers/:customer_id/comm_logs/:id/edit(.:format) {:action=>"edit", :controller=>"comm_logs"}
customer_comm_log GET /customers/:customer_id/comm_logs/:id(.:format) {:action=>"show", :controller=>"comm_logs"}
PUT /customers/:customer_id/comm_logs/:id(.:format) {:action=>"update", :controller=>"comm_logs"}
DELETE /customers/:customer_id/comm_logs/:id(.:format) {:action=>"destroy", :controller=>"comm_logs"}
在現實中,記錄不點擊刪除按鈕後刪除,因爲它是在控制器(顯示頁面的頁面沒有重定向到前一頁只是保持不變,刪除後沒有重定向到任何地方)。看來,刪除操作被路由到了正確的路徑。問題很可能是以下視圖中的link_to:
<%= link_to 'delete', customer_comm_log_path(@customer, @comm_log), :method => :delete, :confirm => "are you sure?", :remote => true %>
link_to上面有什麼問題嗎?謝謝。
你可以發佈你的控制器銷燬方法嗎? – andrewpthorp 2011-12-29 18:23:42