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

Add a slug type field partial? #1232

Open
jagthedrummer opened this issue Dec 6, 2023 · 2 comments · May be fixed by bullet-train-co/bullet_train-core#764
Open

Add a slug type field partial? #1232

jagthedrummer opened this issue Dec 6, 2023 · 2 comments · May be fixed by bullet-train-co/bullet_train-core#764

Comments

@jagthedrummer
Copy link
Contributor

Sometimes models need to have a user-settable url slug, and it might be nice to have this built in to BT.

For instance, if the Team model had a slug you might be able to view a team at /teams/my-team instead of at /teams/a39bc12.

It's kind of just a text_field with some additional requirements and validations (like uniqueness, for example), but there's also the matter of looking up models by slug instead of by id/obfuscated-id, which can be solved by changing to_param.

Maybe this is more application specific than generic and wouldn't be a good addition to BT. Just wanted to throw it out there and see what other people think.

Here's an article that talks about lots of the specific details that we'd need to address if we wanted to do something: https://nts.strzibny.name/activerecord-model-slugs/

@pascallaliberte
Copy link
Member

I feel this should be packaged into the obfuscated_id functionality directly, defaulting to the :slug column, but configurable.

A slug is also a way to obfuscate the id, and to_param and find could be made to prefer the slug if defined, and fall back to the hashId.

@jagthedrummer
Copy link
Contributor Author

Ooooh, that's a good connection, @pascallaliberte! I think you're absolutely right on that.

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

Successfully merging a pull request may close this issue.

2 participants