You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Provide instances with an opportunity to gracefully handle assigning to
an unknown attribute:
```ruby
class Rectangle
include ActiveModel::AttributeAssignment
attr_accessor :length, :width
def attribute_writer_missing(name, value)
Rails.logger.warn "Tried to assign to unknown attribute #{name}"
end
end
rectangle = Rectangle.new
rectangle.assign_attributes(height: 10) # => Logs "Tried to assign to unknown attribute 'height'"
```
By default, classes that do not override `#attribute_writer_missing`
will raise an `ActiveModel::UnknownAttributeError`.
The `attribute_writer_missing` aims to mimic the naming of
`BasicObject#method_missing`. There is also an
[ActiveModel::AttributeMethods#attribute_missing][] method, but that
pertains to attribute _access_.
[ActiveModel::AttributeMethods#attribute_missing]: https://edgeapi.rubyonrails.org/classes/ActiveModel/AttributeMethods.html#method-i-attribute_missing
0 commit comments