At work we use ActiveModel::Serializer to serialize ActiveRecord objects into JSON:API-like responses for our APIs. The problem is that ActiveModel::Serializer is clever enough to dasherize our hash keys (so they can be accessed as properties instead of [] brackets syntax) and our hash keys are actually real keys that we have to serve untouched.
Luckily the solution is more than simple. Insert the following setting into AMS initializer and you are done:
ActiveModelSerializers.config.key_transform = :unaltered
:unaltered
have also the added benefit of being faster as it does not modify anything. I believe it should be default, perhaps it was, I am on version 0.10.5
.
Check out my book
Interested in Ruby on Rails default testing stack? Take Minitest and fixtures for a spin with my latest book.
Get Test Driving Rails while it's in prerelease.