Skip to content

Instantly share code, notes, and snippets.

@mariozig
Created October 8, 2011 20:05
Show Gist options
  • Save mariozig/1272798 to your computer and use it in GitHub Desktop.
Save mariozig/1272798 to your computer and use it in GitHub Desktop.
scoped friendly_id w/ sti
## The setup
# This assumes you already have friendly_id in your gemfile and all that good stuff.
class Car < ActiveRecord::Base
# Slugs via FriendlyId
extend FriendlyId
friendly_id :name, :use => :scoped, :scope => :type
end
class Ford < Car
end
class Toyota < Car
end
## A simple test to make sure it works
t = Toyota.create!(name: "test")
f = Ford.create!(name: "test")
t.slug
=> "test"
f.slug
=> "test"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment