在创建之后,在销毁之前做一些事情

时间:2010-02-08 04:12:26

标签: ruby datamapper

如果创建了一个DataMapper类的实例,并且在它被销毁之前,我怎么能执行一个块执行?

1 个答案:

答案 0 :(得分:4)

假设通过create&销毁你的意思是插入并从数据库中移除...

来自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