Skip to content

Instantly share code, notes, and snippets.

@norman
Created April 3, 2010 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save norman/353932 to your computer and use it in GitHub Desktop.
Save norman/353932 to your computer and use it in GitHub Desktop.
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
@harshamv
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment