删除/销毁在Rails中不起作用

我正在尝试使用我在tags_controller页面中编写的一段代码来使用删除按钮;

def destroy @tag = Tag.find(params[:id]) @tag.destroy redirect_to :back, notice: 'Tag was successfully deleted!' end 

当我从本地主机运行时,它会抛出exception,如下所示;

 Routing Error No route matches [DELETE] "/admin/tags/37/edit" Rails.root: /Users/laurenwoodhams/Desktop/PROJECT/RAILS-BLOG/-t 

这是我的配置路线;

 Rails.application.routes.draw do get '/login' => 'admin/sessions#new' get '/logout' => 'admin/sessions#destroy' namespace :admin do resources :posts resources :tags, except: [:index] resources :sessions, only: [:new, :create, :destroy] resources :administrators, only: [:index, :edit, :update] end end 

您能否检查并解释为什么会发生这种情况?

谢谢

DELETE是HTTP动词(如GET或POST),表示..

要创建删除标记的链接,您需要在视图中执行此类操作。

 <%= link_to "Delete Tag", @tag, method: "delete" %> 

然后它应该正常工作。

PS您可以运行bin/rake routes来查看路线。