Ruby on rails 为什么delete方法在ruby中不起作用

Ruby on rails 为什么delete方法在ruby中不起作用,ruby-on-rails,ruby,Ruby On Rails,Ruby,销毁方法不起作用,但我被重定向到索引页,但记录未被删除 HTML.erb链接: <%= link_to "Delete", posts_path(@post), method: :delete, data: {confirm: 'are you sure?'},:class => 'btn btn-danger' %> posts\u path是指向index操作的路径。将删除链接标记中的posts\u路径更改为post\u路径,以路由到destroy操作 <%= l

销毁方法不起作用,但我被重定向到索引页,但记录未被删除

HTML.erb链接:

<%= link_to "Delete", posts_path(@post), method: :delete, data: {confirm: 'are you sure?'},:class => 'btn btn-danger' %>

posts\u path
是指向
index
操作的路径。将删除链接标记中的
posts\u路径
更改为
post\u路径
,以路由到
destroy
操作

<%= link_to "Delete", post_path(@post), method: :delete, data: {confirm: 'are you sure?'},:class => 'btn btn-danger' %>
“btn btn危险”%>

旁注:使用两个空格进行缩进。
link\u“删除”,post\u路径(@post)
或只
link\u“删除”,@post
使用
method::Delete
依赖javascript(
jquery-ujs
准确)。如果请求作为GET发送(检查日志),则需要检查浏览器控制台中的javascript错误。您还可以使用
按钮_来“删除”、@post
,它创建一个表单,不依赖javascript。当您单击该链接时,您可以发布服务器日志吗。另外,它应该是
post\u路径(@post)
我猜您从
应用程序.js中删除了
jquery-ujs
(或者
rails-ujs
如果rails>5)。你能检查一下那里有没有?这就是处理所有链接单击HTTP方法内容的方法。尝试了代码,但它只是在同一页面中刷新,而没有删除记录。@NidheeshJp如果您不想刷新页面,请将
remote:true
添加到
链接到

<%= link_to "Delete", post_path(@post), method: :delete, data: {confirm: 'are you sure?'},:class => 'btn btn-danger' %>