Topic: How to add delete link to Datatables via json/ajax?

I'm working on a table based on RailsCast #340 on DataTables.

I've added ajax support as Ryan discusses towards the end of the episode.

However, I'm not sure how to add a "delete" link to the json array, because I can't figure out how to include the "method: :delete" part. I'd also like to know how I can pass the Bootstrap class and confirm options.

Here's the view code I'm trying to replicate:

<%= link_to 'Delete', product, method: :delete, class: "btn btn-mini btn-danger", confirm: "You sure?", title: product.product_number %>


Last edited by Brian71 (2012-05-10 13:06:49)

Re: How to add delete link to Datatables via json/ajax?

I found a way to do it by constructing the actual link instead of relying on helpers:

"<a href='/products/""' class='btn btn-mini btn-danger' data-confirm='You sure?' data-method='delete' rel='nofollow' title="+thisproduct.product_number+">Delete</a>"

I'd still be interested in finding out if there's a cleaner way to do this.