我在導軌應用程序中遇到了一些麻煩。我檢查了這個錯誤的其他問題,它們都不適用於我的應用程序。AbstractController :: ActionNotFound - 找不到動作'destroy'
我需要銷燬一行,並做到這一點,我直接在我的控制器內的行爲'毀滅'的形式。
這裏是我指導它的地方。
<%= form_for(:pallet_hist, :url => {:action => 'destroy', :id => params[:id]}) do |f| %>
下面是控制器中的操作。
class PalletHistController < ApplicationController
def destroy
@pallet_hist = PalletHist.find(params[:id]).destroy
flash[:notice] = "Entry '#{pallet_hist.id}' deleted successfully"
redirect_to(:action => 'index', :id => @pallet_hist.pallet_id)
end
end
我不明白爲什麼它仍然給我這個錯誤。
的routes.rb
Rails.application.routes.draw do
match ':controller(/:action(/:id))', :via => [:get, :post]
root 'pallets#index'
end
只是一個簡單的問題,當我將該中間行添加到路由文件中時,我會用什麼替換我的':url => {:action =>'destroy',:id => params [:id]}'? – Padagomez
如果你只需要一個刪除按鈕,那麼你可能不想爲此創建一個表單。你最好使用鏈接。所以這將是這樣的: '<%= link_to'刪除',mycontroller_path(object_to_destroy),方法::刪除%>' – SRod
如果我的答案適合你,這將是很好,如果你可以標記它的最佳答案:) – SRod