我正在努力解决我的新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
查询后记录仍然存在!
答案 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
。