I want to take the results of a pl/pgsql function, that returns a set of records and user AMS to serialize the results. How can I do this?
How to use Active Model Serializer without an Active Record Model?
Asked Answered
AMS can serialize a Plain-Old Ruby Object. AMS provides ActiveModelSerializers::Model
which can easily make a PORO a serializable object by doing this:
class MyModel < ActiveModelSerializers::Model
attributes :id, :name, :level
end
MyModelSerializer would be the default serializer.
Up to date docs: github.com/rails-api/active_model_serializers/tree/… –
Warmonger
I also followed the docs of AMS and tried to do the same but Rails fails to find the serializer:
[active_model_serializers] Rendered ActiveModel::Serializer::Null with User (0.09ms)
. My UserSerializer
looks the same as your MyModel
; What am I missing ? Here is the gist to describe it better. –
Rove © 2022 - 2024 — McMap. All rights reserved.