2017-02-14 34 views
0

控制器銷燬動作不rubyonrails工作

def destroy 
    @idea = Idea.find(params[:id]) 
    @idea.destroy 
    flash[:success] = "The idea was successfully deleted!" 
    redirect_to root_path 
end 

查看

<%= link_to 'Destroy', idea_path(idea), :method => :delete, class: 'btn btn-sm btn-danger', data: {confirm: "Are you sure?"} %> 

爲什麼它不工作?這引發了一些錯誤,如:

ActionController::InvalidAuthenticityToken in IdeasController#destroy 

def handle_unverified_request 
    raise ActionController::InvalidAuthenticityToken 
end 
+1

您是否從應用程序佈局中刪除了<%= csrf_meta_tags%>? – Sculper

+0

是啊!意外。 現在沒事了! 可以告訴我<%= csrf_meta_tags%>的功能嗎? – ibya404

回答

0

在你的控制器,你可以嘗試添加:

skip_before_filter :verify_authenticity_token, only: [:destroy] 

雖然這並不一定能解決問題不亞於就在它得到。