-
-
Save sadjow/6612380 to your computer and use it in GitHub Desktop.
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
# app/models/concerns/slugable.rb | |
module Slugable | |
extend ActiveSupport::Concern | |
included do | |
validates_format_of :slug, :without => /^\d/ | |
before_save :generate_slug | |
end | |
module ClassMethods | |
def find input | |
input.to_i == 0 ? find_by_slug(input) : super | |
end | |
end | |
def generate_slug | |
self.slug = title.parameterize | |
end | |
def to_param | |
slug | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment