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

Rails should append ancestors when generating i18n error messages #26946

Closed
longlostnick opened this issue Oct 31, 2016 · 2 comments
Closed

Rails should append ancestors when generating i18n error messages #26946

longlostnick opened this issue Oct 31, 2016 · 2 comments

Comments

@longlostnick
Copy link

longlostnick commented Oct 31, 2016

Not a bug per say, but I think this could potentially be a good improvement. When generating the key combinations for i18n translation for error messages, instead of building a list of all ancestors it only uses the last one in the list (It's looping through but overriding the previous value on each loop). Since lookup_ancestors generates the list from child > parent (parent being last), I can only specify a translation for the parent class.

https://github.com/rails/rails/blob/master/activemodel/lib/active_model/errors.rb#L389

By pushing onto the array instead of overwriting, this would allow me to (optionally) specify specific keys for STI (children).

For example if I have a class class ClientUser < User right now I the list only includes:

[
  "activerecord.errors.models.user.attributes.LastName.blank",
  "activerecord.errors.models.user.blank"
]

By making this change, the list would include options for the child class as well:

[
  "activerecord.errors.models.client_user.attributes.LastName.blank",
  "activerecord.errors.models.client_user.blank",
  "activerecord.errors.models.user.attributes.LastName.blank",
  "activerecord.errors.models.user.blank"
]
@rafaelfranca
Copy link
Member

Thank you so much for the issue but we don't take feature request on the issue tracker. We recommend you to try to implement the feature and send us a pull request or if you are in doubt if the feature will be accepts ask in Rails Core mailing list for feedback.

@longlostnick
Copy link
Author

@rafaelfranca roger that. Yea that was my main thing. Wanted to make sure it was worthwhile before spending my time w/ the PR. Will check the mailing list. Thx.

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

No branches or pull requests

2 participants