-
Notifications
You must be signed in to change notification settings - Fork 190
Fix model_name availability by explicitly extending ActiveModel::Naming
#335
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
Conversation
In v4.0.0, switching from `extend ActiveModel::Naming` to only `extend ActiveModel::Translation` can cause "undefined method 'model_name'" errors when ActiveHash models include ActiveModel::Serialization, particularly with Rails 8.0+. While ActiveModel::Translation includes ActiveModel::Naming internally, the inclusion doesn't always properly expose the model_name class method when extended. This breaks compatibility for models that depend on model_name being available at the class level. This commit explicitly extends both ActiveModel::Naming and ActiveModel::Translation to ensure model_name is always available while maintaining i18n support. This approach ensures compatibility across all Rails versions. Signed-off-by: moznion <moznion@mail.moznion.net>
|
@flavorjones We're now including |
|
@kbrock I just took a moment to go back and read the prior pull requests, and it seems like these changes are being driven by actual user needs, and it's not adding complexity to the gem. My first reaction, without much thought, is that it's probably OK. That said, I do not fully understand the problem being addressed by this PR. @moznion can you please (at a minimum) help us reproduce what you're seeing in a dev environment? If possible, though, a test would be better. |
|
ok, so this is a swap. Sounds like a straight forward solution. Also, sounds like this is a bug. I also saw one PR asking to add JSON, and worried we are going towards unnecessarily including every module. Helping us come up with a test case would be great. |
…ase does not raise a NoMethodError Signed-off-by: moznion <moznion@mail.moznion.net>
|
@kbrock @flavorjones Thank you for your suggestions. |
kbrock
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for posting this fix
LGTM
|
I appreciate your support. I hope the new version becomes available soon. |
|
@kbrock @flavorjones Hi, could you release a new version including this fix? Thanks! |
In v4.0.0, switching from
extend ActiveModel::Namingto onlyextend ActiveModel::Translation(ref: #230) can cause "undefined method 'model_name'" errors when ActiveHash models includeActiveModel::Serialization, particularly with Rails 8.0+; actually I encountered this problem in our project.While
ActiveModel::TranslationincludesActiveModel::Naminginternally, the inclusion doesn't always properly expose themodel_nameclass method when extended. This breaks compatibility for models that depend onmodel_namebeing available at the class level.This commit explicitly extends both
ActiveModel::NamingandActiveModel::Translationto ensuremodel_nameis always available while maintaining i18n support. This approach ensures compatibility across all Rails versions.