Created
April 3, 2010 00:50
-
-
Save norman/353932 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 MyApp | |
module Friendly | |
def self.included(base) | |
base.has_friendly_id :custom_slug, :use_slug => true, :approximate_ascii => true | |
end | |
def custom_slug | |
if @custom_slug.present? | |
@custom_slug | |
elsif friendly_id | |
friendly_id | |
else | |
FriendlyId::SlugString.new(name).normalize! | |
end | |
end | |
def new_slug_needed? | |
super or @custom_slug != friendly_id | |
end | |
end | |
end | |
class MyModel < ActiveRecord::Base | |
include MyApp::Friendly | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
is there any way to to change the default sluf behaviour when the slug over laps to something shorter that it appends?
harsha mv harsha-mv Show Edit Destroy
harsha mv harsha-mv-d35c5e0a-3fc7-4151-9170-743efebfd004 Show Edit Destroy