I have a Produt model, that if the user left blank, I need to generate a random number. How can I achieve that?
def self.set_random_number()
if self.code == null
self.code.rand(1000..99999)
end
end
I tried this method, and called before_save :set_random_number(). But it doesn't work. Could you guys please help me?
Aucun commentaire:
Enregistrer un commentaire