gpt4 book ai didi

ruby - 在创建之后和销毁之前做一些事情

转载 作者:太空宇宙 更新时间:2023-11-03 18:02:00 25 4
gpt4 key购买 nike

如何在创建 DataMapper 类的实例时执行 block ,并在销毁之前执行另一个 block ?

最佳答案

假设创建和销毁是指从数据库中插入和删除...

来自documentation

 class Post
include DataMapper::Resource

# ... key and properties here

# This record will save properly
before :create do |post|
true
end

# But it will not be destroyed
before :destroy do |post|
throw :halt
end
end

关于ruby - 在创建之后和销毁之前做一些事情,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2219533/

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