fix: handle missing category translations gracefully#830
Open
rewritten wants to merge 2 commits intocoopdevs:developfrom
Open
fix: handle missing category translations gracefully#830rewritten wants to merge 2 commits intocoopdevs:developfrom
rewritten wants to merge 2 commits intocoopdevs:developfrom
Conversation
) Add display_name to Category that falls back to any available translation when the current locale's name is nil or blank, appending [locale] to indicate the language it came from. Fixes crash in all_categories sort when a category is created without a translation for the current locale. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a safer way to render category names when the current locale’s translation is missing, preventing crashes in category filter rendering/sorting.
Changes:
- Introduces
Category#display_namewith a fallback to any available translated name (with a locale indicator). - Updates shared filter partials to use
display_nameinstead ofname. - Adjusts category sorting in
CategoriesHelper#all_categoriesto rely onto_s.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| app/models/category.rb | Adds display_name fallback logic and updates to_s to use it. |
| app/helpers/categories_helper.rb | Changes category sorting to use to_s for downcasing/sorting. |
| app/views/shared/_show_filter_hint.html.erb | Renders the current category via display_name. |
| app/views/shared/_post_filters.html.erb | Uses display_name in the category dropdown and items. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… string - Fall back to Category.model_name.human when no translations exist at all - Use display_name explicitly in helper sort to make crash-safety clear - Use display_name in views for consistent fallback display Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Category#display_namethat falls back to any available translation when the current locale's name is nil or blank[locale]to the displayed name when a fallback is used, so it's clear the name comes from another languagedisplay_nameinstead ofnamedirectlyTest plan
locale=NLwithout filling in a namelocale=ENand visit/offers— no crash, category appears with[nl]suffix if it has a Dutch name, or is sorted to top if truly empty[locale]indicator when viewed in a different locale🤖 Generated with Claude Code