I have the following link:
<a href="/kits?resource_id=536" class="authorize spin" data-method="post" data-remote="true" id="use_it_link_171" rel="nofollow">
After I create the kit I change the link as follows:
<a href="/kits/536" class="authorize spin" data-method="delete" data-remote="true" id="use_it_link_171" rel="nofollow">
I changed the href and the data-method so that it should submit to the destroy action. However its still being submitted as POST
Why is that and how can I fix this so its submits as a ‘delete’?
It’s because Rails uses unobstrusive javascript to set the behavior of tags like
<a data-remote="xxx">or<a data-method="xxx">(in fact Rails creates an hidden form in your page that is submited when the link is clicked). It’s done at page loading by rails.js.So when you change the
data-methodattribute of the link, it’s “too late”, it does not changes the behavior of the link (you should update the hidden form for this). You could dig intorails.jscode to find how to do it, but I suggest that you create 2 links in your page (one withdata-method="post"and one withdata-method="delete"), and use CSS to hide/display only the useful link.