I have an Article model that can have many different types of content blocks. So an Article can have many HeadingBlocks and ParagraphBlocks like this:
class Article < ApplicationRecord
has_many :heading_blocks
has_many :paragraph_blocks
end
class HeadingBlock < ApplicationRecord
belongs_to :article
end
class ParagraphBlock < ApplicationRecord
belongs_to :article
end
I want to be able to alias both HeadingBlock and ParagraphBlock with the same name (blocks) so if I have an instance of an article, I can do something like this:
@article.blocks // returns all heading blocks and paragraph blocks associated
Is this possible in Rails? If so, could you please provide an example on how to alias multiple models in a has many association using the same name?
Thank you.