I'm trying to dry up some code in my Rails application that allows to set a unique id when the object is creating using a filter. I have it in multiple locations and it seems like it should be in a module instead.
Right now I have something like this in each model.
def set_uid
self.uid = SecureRandom.uuid
end
I have included a new file in my /lib directory at the file uid_generator.rb and included that the module in each of the models.
//model
include UidGenerator
module UidGenerator
def set_uid
self.uid = SecureRandom.uuid
end
end
In my testing however, this yields the error
uninitialized constant MODELNAME::UidGenerator (NameError).