我試圖做一個鏈接刪除項目...的link_to破壞GET請求的行動結果
<% @projects.each do |project| %>
<h2><%= project.name %> (<%= project.videos.size %>)</h2>
<%= link_to("Delete!", {:controller=>'projects', :action=>'destroy', :id=>project.hashed_id}, {method: :delete}) %>
<% end %>
不管我做什麼,我得到一個get
請求,所以我最終的項目/顯示視圖。 Urrrgh!
我的控制器:
def destroy
@project = Project.where(:hashed_id=> params[:id]).first.destroy()
flash[:notice]= "Project deleted"
redirect_to(:action=>'index')
end
我缺少什麼?
PS:我發現this,但該解決方案對我無效。
更新
$ rake routes
Prefix Verb URI Pattern Controller#Action
root GET / pages#home
projects GET /projects(.:format) projects#index
POST /projects(.:format) projects#create
new_project GET /projects/new(.:format) projects#new
edit_project GET /projects/:id/edit(.:format) projects#edit
project GET /projects/:id(.:format) projects#show
PATCH /projects/:id(.:format) projects#update
PUT /projects/:id(.:format) projects#update
DELETE /projects/:id(.:format) projects#destroy
更新2 這是我得到的錯誤:
什麼HTML爲link_to呈現? – Fred
您是否嘗試過'link_to(「刪除!」,project_path(project),action :: delete)' – Fred
您是否有公開回購的地方可以看到代碼? –