Robbo
Robbo

Reputation: 1312

Cannot get delete request to work - rails

I have this route:

delete 'basket/remove' => 'flowercard_baskorder#remove', as: :basket_remove

This link in view:

<%= link_to "Remove", basket_remove_path %>

And this in my controller (the binding is just for me to test):

def remove
   binding.pry

end

When the link is clicked on nothing happens and i have no idea why!? I'm obviosuly expecting the binding to kick in but doesn't even look like a request is made?

Cheers

Upvotes: 0

Views: 44

Answers (2)

Cjmarkham
Cjmarkham

Reputation: 9700

You need to pass the method to the link_to function

<%= link_to "Remove", basket_remove_path, method: "delete" %>

Upvotes: 0

Anthony
Anthony

Reputation: 15967

link_to defaults to a get request but you want it to go to a delete right? Just specify that in your call:

<%= link_to "Remove", basket_remove_path, method: :delete %>

Upvotes: 1

Related Questions