Last active
August 29, 2015 13:57
-
-
Save kzaitsev/9703961 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
module Slugeable | |
extend ActiveSupport::Concern | |
included do | |
extend FriendlyId | |
friendly_id :slug_candidates, use: :slugged | |
def slug_candidates | |
if defined?(self.posted_at) | |
"#{posted_at}-#{name}" | |
elsif defined?(self.date) | |
"#{date}-#{name}" | |
else | |
:name | |
end | |
end | |
def normalize_friendly_id(name) | |
if slug.blank? | |
name.to_slug.normalize! :transliterations => :russian | |
else | |
slug.to_slug.normalize! :transliterations => :russian | |
end | |
end | |
def should_generate_new_friendly_id? | |
new_record? || slug.blank? || self.class.find_by_slug(slug).nil? | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment