Created
October 8, 2011 20:05
-
-
Save mariozig/1272798 to your computer and use it in GitHub Desktop.
scoped friendly_id w/ sti
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
## 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