link_to删除方法将我带到导轨上的“显示”页面

问题描述

我是Rails的新手,似乎无法弄清楚

每次我单击链接都不会删除文章,它只会带我进入显示视图。不知道为什么会这样。这是链接的我的代码:

 <%= link_to 'delete',article_path(article.id),method: :delete,data: { confirm: "Are you sure?" } %>

即使我指定了方法(我认为),我的Rails服务器仍显示GET请求:

Started GET "/articles/1" for ::1 at 2020-09-07 10:05:13 -0700
Processing by ArticlesController#show as HTML
  Parameters: {"id"=>"1"}
  Article Load (0.7ms)  SELECT "articles".* FROM "articles" WHERE "articles"."id" = ? LIMIT ?  
  [["id",1],["LIMIT",1]]
  ↳ app/controllers/articles_controller.rb:46:in `set_article'
  Rendering articles/show.html.erb within layouts/application
  Rendered articles/show.html.erb within layouts/application (Duration: 4.0ms | Allocations: 321)
[Webpacker] Everything's up-to-date. Nothing to do
  Rendered layouts/_flashMessages.erb (Duration: 0.2ms | Allocations: 18)
  Rendered layouts/_navBar.html.erb (Duration: 0.1ms | Allocations: 5)
Completed 200 OK in 123ms (Views: 96.9ms | ActiveRecord: 0.7ms | Allocations: 5344)

我不知道为什么。任何帮助表示赞赏。谢谢!

解决方法

我在Rails 6中也遇到了同样的问题。似乎错误的jquery版本可能导致此问题。如果安装了错误的jquery版本,@ rails / ujs会以某种方式正常工作。

如果代码中没有错误,可以尝试通过删除jquery gem并通过yarn(my question concering this topic添加jquery来修复它

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...