我正在尝试删除文档中指定的条目,但我一直收到错误,指出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
我在这里做错了什么?!为什么它被重定向到显示?!
答案 0 :(得分:3)
您错过link_to
致电method: :delete
,否则您会拨打GET电话。