I'm a React and RoR enthusiast with over two years of experience creating innovative software solutions that improve business productivity. I work well in teams and am always up for challenging projects. Born and raised in Pune, I enjoy cooking, painting and travelling in my free time.
1 minute read
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:
To know more about this feature,
checkout this
PR.