omarsafwany
omarsafwany

Reputation: 3811

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?!

Upvotes: 1

Views: 599

Answers (1)

Ursus
Ursus

Reputation: 30056

You missed in your link_tocall the method: :delete, otherwise you do a GET call.

Upvotes: 3

Related Questions