Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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