问题如题,新手一个,跟着 Rails 入门指南学习,但是做到 CRUD 最后的 D 时,发现点击没反应。 (昨天注册的发现没法提问,跟相关贴无人回复,今天发现可以发帖了,惊喜! )
核对了代码,在论坛也搜索了相关问题,发现实现上似乎是没有问题的? 也咨询了 AI,只给出了一些不甚精确、没啥用的解决方案。
试过的可能办法:
所以实在无可奈何,请教下这里的大神们有没有相关的经验解决?
相关代码实现如下:
views/articles/show.html.erb
<li><%= link_to "Destroy", article_path(@article), data: {
turbo_method: :delete,
turbo_confirm: "Are you sure?"
} %></li>
controllers/articles_controller.rb
def destroy
@article = Article.find(params[:id])
@article.destroy
redirect_to root_path, status: :see_other
end
点击 Destroy 时 rails 终端控制台的输出:
Started GET "/articles/2" for 114.242.67.194 at 2025-01-07 17:39:21 +0800
Cannot render console from 114.242.67.194! Allowed networks: 127.0.0.0/127.255.255.255, ::1
Processing by ArticlesController#show as HTML
Parameters: {"id"=>"2"}
Article Load (0.1ms) SELECT "articles".* FROM "articles" WHERE "articles"."id" = ? LIMIT ? [["id", 2], ["LIMIT", 1]]
↳ app/controllers/articles_controller.rb:9:in `show'
Rendering layout layouts/application.html.erb
Rendering articles/show.html.erb within layouts/application
Rendered articles/show.html.erb within layouts/application (Duration: 0.2ms | Allocations: 91)
Rendered layout layouts/application.html.erb (Duration: 2.0ms | Allocations: 1274)
Completed 200 OK in 4ms (Views: 2.4ms | ActiveRecord: 0.1ms | Allocations: 2058)
个人看起来似乎是 DELETE 方法未生效?有没有大神指点一下