Skip to content

Commit fe29d65

Browse files
committed
Fix model_name availability when using ActiveModel::Serialization
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 <[email protected]>
1 parent c2582a7 commit fe29d65

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

lib/active_hash/base.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Base
2424
class_attribute :_data, :dirty, :default_attributes, :scopes
2525

2626
if Object.const_defined?(:ActiveModel)
27+
extend ActiveModel::Naming
2728
extend ActiveModel::Translation
2829
include ActiveModel::Conversion
2930
else

0 commit comments

Comments
 (0)