Created
November 22, 2012 15:39
-
-
Save dblock/4131766 to your computer and use it in GitHub Desktop.
Monkey-patch mongoid-slug to allow slug = _id
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 Mongoid | |
module Slug | |
class UniqueSlug | |
alias_method :_find_unique, :find_unique | |
# by default Mongoid::Slug returns id-1 if you try to get a slug from the model's ID | |
def find_unique attempt = nil | |
if ! attempt | |
candidate = url_builder.call(model) | |
return candidate if candidate == model.id.to_s | |
end | |
_find_unique attempt | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See a discussion on allowing IDs as slug in mongoid/mongoid-slug#91.