Sha256: 9bc9a380b324886f45024cc831093d105a1db072898e895b845d4448be968bf2
Contents?: true
Size: 588 Bytes
Versions: 27
Compression:
Stored size: 588 Bytes
Contents
module MinimumViableProduct module Slugification extend ActiveSupport::Concern module ClassMethods def slugify(name, opts={}) _opts = opts.reverse_merge(:if => lambda{ |obj| obj.send("#{name}_changed?".to_sym) }) before_validation -> { self.slug = slugify(self.send(name.to_sym)) self.slug += SecureRandom.uuid if self.class.find_by(slug: self.slug).present? }, _opts end end private def slugify(str) str.gsub(/[^a-zA-Z0-9]+/,'-') .gsub(/^[-]+|[-]+$/,'') .downcase end end end
Version data entries
27 entries across 27 versions & 1 rubygems