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 |
# File 'app/models/concerns/minimum_viable_product/slugification.rb', line 6 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 |