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

36 weergaven
Naar het eerste ongelezen bericht

Daniel White

ongelezen,
31 jul 2014, 15:02:5131-07-2014
aan 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
Allen beantwoorden
Auteur beantwoorden
Doorsturen
0 nieuwe berichten