Do something after creating, and before destroying
-
19-09-2019 - |
Question
How can I have a block execute whenever an instance of a DataMapper class is a created, and another before it is destroyed?
Solution
Assuming by create & destroy you mean insert and remove from the db...
From the 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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow