Create Sluggable concern, generates slug using name attribute before validation

Why:

* We need a way to generate a slug for a object given his name attribute value

How:

* A concern that generates the slug before validation
This commit is contained in:
Bertocq
2017-07-04 14:18:54 +02:00
parent 73e0a5a88d
commit 4535fc9345

View File

@@ -0,0 +1,11 @@
module Sluggable
extend ActiveSupport::Concern
included do
before_validation :generate_slug
end
def generate_slug
self.slug = name.to_s.parameterize
end
end