简体   繁体   中英

Rails - delete method not working

I am trying to delete an entry as specified in the docs but I keep getting en error stating NoMethodError in Tasks#show and the entry is not deleted.

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

What am I doing wrong here?! and why does it get redirected to show?!

你错过了你的link_to调用method: :delete ,否则你进行GET调用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM