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

fix: translation_key class attribute #3565

Merged
merged 4 commits into from
Jan 7, 2025

Conversation

Paul-Bob
Copy link
Contributor

@Paul-Bob Paul-Bob commented Dec 31, 2024

Description

Fixes #3538

The translation_key method defined in the base resource relied on an instance attribute, @translation_key, which was always nil.

    class << self
        def translation_key
          @translation_key || "avo.resource_translations.#{class_name.underscore}"
        end
    end

Previously, a bug in Rails (prior to this Rails PR) inadvertently redefined the class attribute reader for all sub-classes that defined the class attribute, causing translation_key to exhibit the expected behavior by chance. After the fix in Rails 8.0.1, the correct reader from the parent class is now used. However, since @translation_key is an instance attribute rather than a class-level attribute, it remains nil, and the method defaults to the fallback value. Check rails/rails#53992 for more details.

To fix this, I renamed the class attribute to custom_translation_key and aliased the writer to translation_key for backward compatibility.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

@Paul-Bob Paul-Bob added the Fix label Dec 31, 2024
@Paul-Bob Paul-Bob self-assigned this Dec 31, 2024
Copy link

codeclimate bot commented Dec 31, 2024

Code Climate has analyzed commit ab8fd46 and detected 0 issues on this pull request.

View more on Code Climate.

@Paul-Bob Paul-Bob merged commit ad05ff8 into main Jan 7, 2025
20 checks passed
@Paul-Bob Paul-Bob deleted the fix/translation_key_class_attribute branch January 7, 2025 10:17
Copy link
Contributor

github-actions bot commented Jan 7, 2025

This PR has been merged into main. The functionality will be available in the next release.

Please check the release guide for more information.

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

Successfully merging this pull request may close these issues.

Resource translation_key is being disregarded with Rails 8.0.1
1 participant