method: :delete
I’m sure we’ve all seen the following code before:
<%= link_to “Destroy”, my_object, method: :delete %>
minus the new hash calls in 1.9.2, this is a pretty standard delete link rails. Here’s the issue though, links can’t make actually delete requests so how does this work exactly?
What rails is doing, is on the fly, if you’ve added this method, its actually makes your application execute a javascript function when clicked that then creates a delete request on the server side so that the routes work properly. The only downside to this is that if your users don’t have javascript running, this links fails epically. If you have users who don’t use javascript you basically have two options:
- Use button_to, this will create a whole form which actually allows the delete request and does not require javascript
- Ignore those users. They’re weird anyway
Personally, I’d opt for two but the choice is yours. Either way, you should be aware of what you are presenting to users.