How can I check the serialization of an active model serializer in the command line?
$ rails c
> ModelSerializer.new(Model.last)
=> # does not give me the custom format of my serializer
How can I check the serialization of an active model serializer in the command line?
$ rails c
> ModelSerializer.new(Model.last)
=> # does not give me the custom format of my serializer
You are missing the call to to_json
.
ModelSerializer.new(Model.last).to_json
to properly view it in irb
use puts
puts ModelSerializer.new(Model.last).to_json
You can also use as_json
or serializable_attributes
to get the attributes as Hash
. Not surprisingly, these methods use the same naming of the built-in serialization methods in an ActiveRecord
model.
Note that if you are using AMS version 0.10.x, you need to do the following to get the hash from outside a Rails controller:
ActiveModel::SerializableResource.new(Model.last).serializable_hash