问题描述
我是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来修复它