我正在尝试创建链接以删除项目...
<% @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
请求,所以我最终会进入项目/展示视图。呃!
我的控制器:
def destroy
@project = Project.where( :hashed_id=> params[:id]).first.destroy()
flash[:notice]= "Project deleted"
redirect_to(:action=>'index')
end
我错过了什么?
PS:我找到了这个,但该解决方案对我不起作用。
更新
$ 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 这是我得到的错误: