Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Monkey-patch mongoid-slug to allow slug = _id
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
@dblock
Copy link
Author

dblock commented Nov 22, 2012

See a discussion on allowing IDs as slug in mongoid/mongoid-slug#91.

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