As we all know, in REST the ResourceController#delete action is called
by calling "/resources/:id" with a delete method. But, the delete
method is not supported in IE. This seems like a problem to me. How do
people get around this, typically? I can think of various ways around
it but they all seem a bit bodgy and i'd like to know some other
approaches or even if there's something really obvious that i'm missing.
Hi,
You just cat you following in your view:
<%= link_to 'Destroy', photo, :confirm => 'Are you sure?', :method
=> :delete %>
and it appear in browser to that:
<a onclick="if (confirm('Are you sure?')) { var f =
document.createElement('form'); f.style.display = 'none';
this.parentNode.appendChild(f); f.method = 'POST'; f.action =
this.href;var m = document.createElement('input');
m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method');
m.setAttribute('value', 'delete'); f.appendChild(m);var s =
document.createElement('input'); s.setAttribute('type', 'hidden');
s.setAttribute('name', 'authenticity_token'); s.setAttribute('value',
'LgNwcxaXQ3+NT95f1SJYo1ZOUfXMFtQimzSzDmjJM3g=');
f.appendChild(s);f.submit(); };return false;" href="/photos/
51">Destroy</a>
as you can see its still post, but it has hidden input that tells your
controller about delete.
Hi,
You just cat you following in your view:
<%= link_to 'Destroy', photo, :confirm => 'Are you sure?', :method
=> :delete %>
and it appear in browser to that:
<a onclick="if (confirm('Are you sure?')) { var f =
document.createElement('form'); f.style.display = 'none';
this.parentNode.appendChild(f); f.method = 'POST'; f.action =
this.href;var m = document.createElement('input');
m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method');
m.setAttribute('value', 'delete'); f.appendChild(m);var s =
document.createElement('input'); s.setAttribute('type', 'hidden');
s.setAttribute('name', 'authenticity_token'); s.setAttribute('value',
'LgNwcxaXQ3+NT95f1SJYo1ZOUfXMFtQimzSzDmjJM3g=');
f.appendChild(s);f.submit(); };return false;" href="/photos/
51">Destroy</a>
as you can see its still post, but it has hidden input that tells your
controller about delete.
Ah yes, of course, i had the feeling that rails handled this with a bit
of subterfuge but couldn't remember quite how. I actually tried this
with a link_to_remote and the generated html was just a call to
jQuery.ajax with the delete method, just as i'd done it already, rather
than the code you posted up. I wonder if this is an issue with the
jrails plugin, which overrides the javascript generated by rails' remote
helpers.
I'm actually doing it in javascript (in a jQuery.ajax call) anyway, so
lets see if changing the method to post and adding "_method=delete" to
the data has the same effect...yes it does. Great, thanks Dmitry!