【发布时间】:2022-12-18 09:38:55
【问题描述】:
我正试图破坏我的负债表中的一条记录。在这个表中有一个 person 和 page 字段。我正在尝试查找 ID 为 5 且显示页面的责任记录。
person = person.find_by_id(5)
page = Liability.where(page: 'show')
if person == 5
page.destroy
end
这不会删除记录。为什么?
【问题讨论】:
-
Liability.where(page: 'show') 返回 ActiveRecord 关联,而不是模型。需要 Liability.where(page: 'show').first
-
你是说
destroy_all? -
destroy_all 也不会删除记录
标签: ruby-on-rails ruby