Rails 3:脚手架销毁动作重定向以显示动作

发布于 2024-11-06 21:57:20 字数 218 浏览 1 评论 0原文

我创建了一个简单的脚手架,问题是当我尝试删除一条记录时单击 destroy Rails 重定向到显示操作,这是我生成脚手架时自动生成的链接的代码:

<%= link_to 'Destroy', product, :confirm => 'Are you sure?', :method => :delete %> 

出了什么问题?

i created a simple scaffold, the problem is that when i try to delete a record click destroy rails redirect to the show action, this is the code of the link generated automatically when i generate the scaffold:

<%= link_to 'Destroy', product, :confirm => 'Are you sure?', :method => :delete %> 

what's wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无名指的心愿 2024-11-13 21:57:20

您需要将 rails.js 包含在您的应用程序布局中,因为此链接需要 JS 使用正确的 HTTP 方法。另请确保您的布局中有 csrf_meta_tag

You need to have rails.js included in your application layout, as this link require JS to use the correct HTTP method. Also make sure you have the csrf_meta_tag in your layout.

原谅我要高飞 2024-11-13 21:57:20

检查您的 application.js 是否有 //= require jquery_ujs

Check if your application.js has //= require jquery_ujs

活泼老夫 2024-11-13 21:57:20

application.js中添加这段代码

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require_tree .

Add in application.js this code

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require_tree .
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文