控制器
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
答案 0 :(得分:0)
在您的控制器中,您可以尝试添加:
skip_before_filter :verify_authenticity_token, only: [:destroy]
虽然这并不一定能解决问题,只是绕过它。