Last active
November 16, 2018 06:45
-
-
Save rastamhadi/cd02f70b3313b5488c85014554b8f3dd to your computer and use it in GitHub Desktop.
Hacking ActiveModelSerializers to serialize Null Objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ActiveModelSerializers.config.serializer_lookup_chain.unshift( | |
| lambda do |resource_class, serializer_class, namespace| | |
| # Maps Foo::Bar to FooSerializer | |
| parent_module_name = resource_class.name.deconstantize | |
| [serializer_class, namespace].map do |m| | |
| "#{m}::#{parent_module_name}Serializer" | |
| end | |
| end | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment