Code Monkey home page Code Monkey logo

Comments (3)

dblock avatar dblock commented on July 26, 2024

I would remove mongoid-slug and add field :_slugs, type: Array, ensure that there's an index with index :_slugs, unique: true and reimplement a lookup in a higher level of the application that falls back to _slugs whenever something doesn't look like an ID and/or cannot be found, followed by a 301 permanent redirect.

Does that help?

from mongoid-slug.

geraldhiller avatar geraldhiller commented on July 26, 2024

It's definitely a good solution. I guess I was hoping for a built-in mechanism to achieve this kind of behavior. Like a "disabled" flag that you can set on the slug field so that the reverse lookup would still work, but the default id field gets served as the slug from now on. But probably my case is not common enough to warrant an option like that.

The problem for me with your solution is that I'm hesitant to add extra code just to achieve this behavior. So if there is no built-in solution, I am tending towards simply disabling the slugs and having to live with the lost history, whatever repercussions that may entail with Google.

from mongoid-slug.

dblock avatar dblock commented on July 26, 2024

Feel free to PR something that accomplishes that. Instead of a disabled function I would want to split up the Mongoid::Slug module into a Mongoid::Slug::Find and Mongoid::Slug::Create so that you can include one, the other or both functionalities. Will leave this open as a feature request.

Other than above, you can roll your own Mongoid::Slug that just implements the find part and you won't have to change anything in your classes after removing the gem.

from mongoid-slug.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.