Is it possible to define a before_save callback in a module? Such that with a class like this:
class Model
include MongoMapper::Document
include MyModule
end
and a module like this:
module MyModule
before_save :do_something
def do_something
#do whatever
end
end
do_something will be called before any Model objects are saved? I’ve tried it like this but get undefined method 'before_save' for MyModule:Module.
Apologies if it’s something simple – I’m new to Ruby and to Rails.
In Ruby on Rails < 3 (without Rails features, only Ruby)
In Ruby on Rails >= 3 (with Rails
Concernfeature)