Feature: Ability to move common attributes and functions into a Concern

36 views
Skip to first unread message

Daniel White

unread,
Jul 31, 2014, 3:02:51 PM7/31/14
to rails-a...@googlegroups.com
I often find myself duplicating many attributes and functionality across different serializers. Normally I'm able to remove duplication using inheritance with a common base serializer. However, inheritance isn't always a logical or best answer.

For example, with the popular `paper_trail` gem many non-related models end up with a similar has_many relationship to `Versions` model. Instead of putting `has_many :versions, embed: :ids, include: true` in every model with a paper trail, I could include a common Concern HasPaperTrail that manages the versions relationship.

Anytime a Concern or polymorphic relationship makes sense in ActiveModel, it might also make sense to use a common serilizer Concern to handle it's serilization.

Thoughts?

Thank you for reading,
-Daniel
Reply all
Reply to author
Forward
0 new messages