Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abandoning slugs while keeping slug history #250

Open
geraldhiller opened this issue Jun 13, 2018 · 3 comments
Open

Abandoning slugs while keeping slug history #250

geraldhiller opened this issue Jun 13, 2018 · 3 comments

Comments

@geraldhiller
Copy link

This is more of a question regarding a best/good practice than an issue.

I've been using mongoid_slugs for a while on my website. Now I would like to remove them and to switch back to using the db ids. I could remove the slugs keyword and the include statement from my model to get the result I want. But this would make me lose my slug history, which I don't want, as that could have unforseen negative consequences with Google.

What's the best practice for abandoning slugs while keeping the slug history?

I tried using slug :id, history: true but this suffixes my slugs with -1 58519083934c2b39e6c49a73-1, as it should if the id is in the slug table by default - although it does not get listed on document.slugs. What I am looking for is a way to tell mongoid_slug to use the id as the slug, instead of the last item of the slugs array.

@dblock
Copy link
Collaborator

dblock commented Jun 14, 2018

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?

@geraldhiller
Copy link
Author

geraldhiller commented Jun 28, 2018

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.

@dblock
Copy link
Collaborator

dblock commented Jun 28, 2018

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.

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

No branches or pull requests

2 participants