开发者

Rail delete/destroy method won't work with jquery

开发者 https://www.devze.com 2023-02-09 22:37 出处:网络
Putting jquery.js in the application.html.erb will disable the destroy/delete functionality. Following code html code, generated from <%= link_to \'D\', word_path(word), :confirm => \'A开发者_

Putting jquery.js in the application.html.erb will disable the destroy/delete functionality.

Following code html code, generated from <%= link_to 'D', word_path(word), :confirm => 'A开发者_开发知识库re you sure?', :method => :delete %>, when clicked, show action ,instead of destroy will be called, and no confirmation window anymore.

<a href="/words/3" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Delete</a>

Any ideas? Is it a bug?


In Rails3 you need to add the following tag in your to perform a delete

<%= csrf_meta_tag %>

As described in the railscast http://asciicasts.com/episodes/205-unobtrusive-javascript

Hope this helps.


<%= link_to 'D', word_path(word), :confirm => 'Are you sure?', :method => :delete %>

For this you dont need to add "word_path" just add

<%= link_to 'D', word, :confirm => 'Are you sure?', :method => :delete %>

and it will work like a charm

0

精彩评论

暂无评论...
验证码 换一张
取 消