Module: MinimumViableProduct::Slugification::ClassMethods
- Defined in:
- app/models/concerns/minimum_viable_product/slugification.rb
Instance Method Summary collapse
Instance Method Details
#slugify(name, opts = {}) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'app/models/concerns/minimum_viable_product/slugification.rb', line 6 def slugify(name, opts={}) before_validation -> { return true if self.slug.present? self.slug = slugify(self.send(name.to_sym)) self.slug += "-#{SecureRandom.uuid}" if self.class.find_by(slug: self.slug).present? }, opts validates :slug, uniqueness: true end |