Rails - 删除方法不起作用

时间:2016-06-01 19:47:50

标签: ruby-on-rails ruby

我正在尝试删除文档中指定的条目,但我一直收到错误,指出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

我在这里做错了什么?!为什么它被重定向到显示?!

1 个答案:

答案 0 :(得分:3)

您错过link_to致电method: :delete,否则您会拨打GET电话。