"8"} -6ren">
gpt4 book ai didi

ruby-on-rails - 依赖 : :destroy doesn't work (has_many association)

转载 作者:行者123 更新时间:2023-12-03 15:45:44 25 4
gpt4 key购买 nike

我的问题就像这个线程的标题一样简单
我有两个类

class Category < ActiveRecord::Base

has_many :subcategories, dependent: :destroy

accepts_nested_attributes_for :subcategories

end

class Subcategory < ActiveRecord::Base
belongs_to :category
end

但是当我点击 link_to "Delete", category_path(category), method: :delete请求的类别被销毁,但所有子类别都保持原样。

编辑

服务器日志:
Started DELETE "/categories/8" for 127.0.0.1 at 2013-10-29 01:38:01 +0100
Processing by CategoriesController#destroy as HTML
Parameters: {"authenticity_token"=>"rOTo3ROv/QsQRMPyCljbMvrViKgihC1CowBdlHdq7O4=", "id"=>"8"}
Category Load (0.3ms) SELECT `categories`.* FROM `categories` WHERE `categories`.`id` = 8 LIMIT 1
SQL (0.5ms) DELETE FROM `categories` WHERE `categories`.`id` = 8
Redirected to http://localhost:3000/categories
Completed 302 Found in 3ms (ActiveRecord: 0.8ms)


Started GET "/categories" for 127.0.0.1 at 2013-10-29 01:38:01 +0100
Processing by CategoriesController#index as HTML
Category Load (0.3ms) SELECT `categories`.* FROM `categories`
Rendered categories/index.html.haml within layouts/application (0.9ms)
Rendered application/_header.html.haml (0.1ms)
Completed 200 OK in 6ms (Views: 5.5ms | ActiveRecord: 0.3ms)

最佳答案

您在打电话吗delete在类别上?你应该打电话destroy反而。

关于ruby-on-rails - 依赖 : :destroy doesn't work (has_many association),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19647519/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com