Last active
August 26, 2018 20:40
-
-
Save rafaels88/5529b3863c699b1cd4d20265c32d4a21 to your computer and use it in GitHub Desktop.
Hanami Sluggable (Slugify) Module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/your_app/ext/sluggable.rb | |
module Sluggable | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
def sluggable(field) | |
@field = field | |
end | |
def field | |
@field | |
end | |
end | |
def slug | |
send(self.class.field).slugify | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
USAGE
Do not forget to create :slug field in database and mapping it to its entity