Skip to content

Instantly share code, notes, and snippets.

@dblock
Created November 22, 2012 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dblock/4131766 to your computer and use it in GitHub Desktop.
Save dblock/4131766 to your computer and use it in GitHub Desktop.
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