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:
11
app/models/concerns/sluggable.rb
Normal file
11
app/models/concerns/sluggable.rb
Normal 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
|
||||||
Reference in New Issue
Block a user