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

[#285] Add Friendly ID gem #7735

Merged
merged 3 commits into from
Jun 30, 2023
Merged

[#285] Add Friendly ID gem #7735

merged 3 commits into from
Jun 30, 2023

Conversation

gbp
Copy link
Member

@gbp gbp commented May 9, 2023

Relevant issue(s)

Requires #7702
Connected to #285

What does this do?

  • Adds the friendly_id gem
  • Uses this gem over our own implementation for User#url_name generation
  • Adds migration from the current column to the FriendlyID::Slug model.

Why was this needed?

To allow user to change their names without breaking URLs. The friendly_id gem will store old slugs and correctly load the record if the old URL is hit.

Implementation notes

Unfortunately we need to override some of friendly_id internal methods until we do the next release.

Copy link
Member

@garethrees garethrees left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Could probably do with a quick chat through how it all works, but seems to be working fine in practice 🐌

lib/tasks/temp.rake Outdated Show resolved Hide resolved
@gbp gbp linked an issue May 30, 2023 that may be closed by this pull request
gbp added 3 commits June 20, 2023 07:54
Used to store `User#url_name` slugs in a separate model retaining
history and the ability to load users using old slugs.

Configuration is in an `User::Slug` module instead of the initializer as
we could potentially use this for other models which store slugs. EG
`InfoRequest` or `PublicBody`.
Needs to override some internal friendly_id methods to use the
non-history module version.

These methods relate to the generation and searching for slugs as this
will currently fail due to history module expecting this information to
be in `FriendlyID::Slug` instances but until we migrate the existing
records to this model is doesn't exist.

We will add a `temporary` rake task to migrate slugs.
Current `url_name` need to be stored as slugs in order to correctly
generate slugs and find User instances.
@gbp gbp force-pushed the 285-friendly-id branch from 72acddb to f9b5603 Compare June 20, 2023 06:55
@gbp gbp marked this pull request as ready for review June 20, 2023 06:55
@gbp gbp merged commit 9089fbe into develop Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Username change without changing history
2 participants