From ec60f7fb4be7213174f150318e418cdd8832a39b Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Thu, 16 Mar 2023 20:36:24 -0600 Subject: Añade código de ProductsController MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/product.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'app/models/product.rb') diff --git a/app/models/product.rb b/app/models/product.rb index 72d7f33..87a7a71 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -21,5 +21,17 @@ class Product < ApplicationRecord has_one_attached :picture + around_create :generate_public_id + serialize :categories, Array + + def to_param + public_id + end + + private + + def generate_public_id + self.public_id = SecureRandom.hex(12) + end end -- cgit v1.2.3