I want to execute a method before each class method. Is it possible to do this using ActiveModel callbacks or do i have to use metaprogramming ?
I tried :
class Image
extend ActiveModel::Callbacks
define_model_callbacks :create
before_create :set_base_uri
def self.create
run_callbacks :create do
..my_code..
end
end
def set_base_uri
..my_code..
end
end
When i call Image.create
i get
undefined method `run_callbacks' for Image:Class
The same code works if i change create
to an instance method. I looked at the documentation but they don't mention class methods, does ActiveModel support class methods callbacks ?