Rails 6.1 added delegated_type which resembles polymorphic relations. Using delegated_type the developer is introduced with a bunch of useful methods and scopes. Checkout this PR to know more about this feature.

Before

For the sake of understanding, let’s consider the following declaration of the Note model.

Previously, in order to create a new delegated_type record, we would do something like this:

If we try to save the note using nested attributes, it will raise an error:

After

With Rails 7 adding support of accepts_nested_attributes_for for delegated_type we can save the records as follows: