如果创建了一个DataMapper类的实例,并且在它被销毁之前,我怎么能执行一个块执行?
答案 0 :(得分:4)
假设通过create&销毁你的意思是插入并从数据库中移除...
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