instance method
subclass_from_attributes
Ruby on Rails 8.1.2
Since v4.0.13 PrivateSignature
subclass_from_attributes(attrs)
Detect the subclass from the inheritance column of attrs. If the inheritance column value is not self or a valid subclass, raises ActiveRecord::SubclassNotFound
Parameters
-
attrsreq
Source
# File activerecord/lib/active_record/inheritance.rb, line 331
def subclass_from_attributes(attrs)
attrs = attrs.to_h if attrs.respond_to?(:permitted?)
if attrs.is_a?(Hash)
subclass_name = attrs[inheritance_column] || attrs[inheritance_column.to_sym]
if subclass_name.present?
find_sti_class(subclass_name)
end
end
end
Defined in activerecord/lib/active_record/inheritance.rb line 331
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Inheritance::ClassMethods