Sha256: de51ce092afaa590be29e88f61a97a8eac15a19eaf22d70c4ca2feb86ad8dcb9
Contents?: true
Size: 379 Bytes
Versions: 21
Compression:
Stored size: 379 Bytes
Contents
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)) }, _opts end end private def slugify(str) str.gsub(/\s/,'_').dasherize.downcase end end
Version data entries
21 entries across 20 versions & 2 rubygems