Rails 3:scaffold destroy action重定向以显示动作

时间:2011-05-12 10:34:06

标签: ruby-on-rails-3 action scaffold

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

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

出了什么问题?

3 个答案:

答案 0 :(得分:5)

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

答案 1 :(得分:2)

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

答案 2 :(得分:0)

添加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 .