Skip to content

Commit

Permalink
If an attribute alias reaches method missing, send the original
Browse files Browse the repository at this point in the history
  • Loading branch information
justinko committed May 4, 2024
1 parent 793ff00 commit 9bf3b96
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions activemodel/lib/active_model/attribute_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,14 @@ def method_missing(method, ...)
if respond_to_without_attributes?(method, true)
super
else
match = matched_attribute_method(method.name)
match ? attribute_missing(match, ...) : super
# If the missing method is an attribute alias, let's send the original
# to +method_missing+ since it can actually produce a value.
if self.class.attribute_alias?(method) && self.class.send(:instance_method_already_implemented?, method)
super(self.class.attribute_alias(method).to_sym, ...)
else
match = matched_attribute_method(method.name)
match ? attribute_missing(match, ...) : super
end
end
end

Expand Down

0 comments on commit 9bf3b96

Please sign in to comment.