[英]Rails - delete method not working
我正在尝试删除文档中指定的条目,但我一直在错误中声明NoMethodError in Tasks#show
并且该条目未被删除。
index.html.erb:
<%= link_to 'Delete', destroy_task_path(task['id']), data: { confirm: 'Are you sure?' } %>
route.rb:
delete '/tasks/:id', to: 'tasks#destroy', as: 'destroy_task'
resources :tasks
root 'home#index'
tasks_controller.rb
def destroy
uri = URI.parse("http://localhost/tasks/public/api/tasks/"+params[:id])
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Delete.new(uri.path)
redirect_to :tasks, notice: 'Task was successfully destroyed.'
end
我在这做错了什么?! 为什么它被重定向到显示?!
你错过了你的link_to
调用method: :delete
,否则你进行GET调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.