i have a model. i want import in this model a module. in this module i want insert a validates_presence_of for the models that import it
I want know if and how is possible to do something like this:
class Ele < ActiveRecord::Base
include Mod
end
module Mod
validates_presence_of :field
end
Thanks
You can use the self.included
hook.
class Ele < ActiveRecord::Base
include Mod
end
module Mod
def self.included(base)
base.class_eval do
validates_presence_of :field
end
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With