There's something super elegant about Writebook's
use of concerns. I especially like Book:Sluggable
:
module Book::Sluggable
extend ActiveSupport::Concern
included do
before_save :generate_slug, if: -> { slug.blank? }
end
def generate_slug
self.slug = title.parameterize
end
end
Here's a few reasons:
app/models/book/sluggable.rb
.