2012-05-18 22 views
0

的link_to刪除重定向展現行動,而不是去破壞鐵軌行動3.1.1錯誤:刪除的link_to重定向到顯示行動,而不是去破壞鐵軌行動3.1.1

這裏是我的代碼

查看: -

:delete, :confirm => "Are you sure..!", :alt => "Delete", :title => "Delete" %>

控制器: -

def destroy @industry = Industry.find(params[:id]) if @industry.destroy flash[:notice] = "Successfully deleted industry with name #{@industry.name}" else flash[:error] = "Error Occurred while deleting industry. Please try again." end redirect_to industries_path
end

+0

給route.rb的代碼和代碼的link_to。 –

+1

這裏的意見查看次數 <%= link_to「Delete」,industry_path(industry.id),:method =>:delete,:confirm =>「Are you sure ..!」,:alt =>「Delete」 ,:title =>「刪除」%> – devudilip

+0

請給出路由信息。您可以使用(從終端)'$ CONTROLLER = controller_name rake routes'來列出路由。 –

回答

2

你甲肝e加載了默認的JavaScript庫嗎?

如果沒有,那就是爲什麼 - 你不能通過瀏覽器發送DELETE請求,因爲它不被支持 - 所以當點擊刪除鏈接時,Rails會自動創建一個表單並以這種方式發送。但它使用JS來完成,所以如果沒有加載,你什麼也得不到。

+0

您好Stephen 我使用rails 3.1.1,因爲它沒有任何默認的JavaScript文件。 我嘗試在app/assets/javascripts中包含rails.js文件,還包含 <%= javascript_include_tag「application」,「rails」%> layouts/application.html.erb – devudilip

0

檢查下面的代碼,如果有

DELETE /industry/:id destroy . 

路線然後

<%= link_to 'Destroy', industry, confirm: 'Are you sure?', 
            method: :delete %>