Sha256: 96ba0797d378172d9d1d9a5b2a78f8c3f6436cc8efab60554ffd7dcb8f0d0c4c
Contents?: true
Size: 544 Bytes
Versions: 4
Compression:
Stored size: 544 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]/,'-').downcase end end end
Version data entries
4 entries across 4 versions & 1 rubygems