Rails 4摧毁行动不起作用

时间:2013-12-19 18:10:11

标签: ruby-on-rails

我正在努力解决我的新cmd的烦人问题:方法销毁无法正常工作。一切看起来都不错,这是日志:

Started DELETE "/admin/videos/1" for 127.0.0.1 at 2013-12-19 19:02:53 +0100
Processing by Admin::VideosController#destroy as HTML
  Parameters: {"authenticity_token"=>"yIFTvqxF+ablO8xakneLmlUBLyewaH2syX2Q6QE+9rQ=", "id"=>"1"}
  User Load (0.9ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
Redirected to http://localhost:3000/admin/videos
Completed 302 Found in 5ms (ActiveRecord: 0.9ms)

我的链接是:

= link_to admin_video_path(video), method: :delete, title: "Delete" do
  %i.fa.fa-trash-o
  Canc

查询后记录仍然存在!

2 个答案:

答案 0 :(得分:0)

这是destroy方法应该如何显示的示例代码(在控制器内部):

def destroy
    modelnamehere.find(params[:id]).destroy
    flash[:success] = "modelnamehere deleted."
    redirect_to modelnamehere_url
end

答案 1 :(得分:0)

确保您没有before_destroy回调,除了true之外没有返回任何内容。即使无意中返回nil也会阻止destroy方法在停止方法链时成功执行。

tl; dr 确保任何成功案例的before_destroy回调始终返回true