I am trying to send a serialized version of a model to a view as a parameter using gem active_model_serializers
Above debugs give the answer below:
--- '{"data":{"id":"1","type":"admins","attributes":{"email":"tech@bluesapling.com","access_locked?":false}}}' //returned by the first debug --- - '{"object":{"id":36,"email":"aubrey_schmitt@feeneykoch.io","created_at":"2016-03-28T05:15:17.546Z","updated_at":"2016-03-28T05:15:17.546Z"},"instance_options":{},"root":null,"scope":null}' - '{"object":{"id":20,"email":"alysa_johnston@thompson.io","created_at":"2016-03-28T05:15:16.304Z","updated_at":"2016-03-28T05:15:16.304Z"},"instance_options":{},"root":null,"scope":null}' - '{"object":{"id":22,"email":"kristofer.langosh@kunzeluettgen.com","created_at":"2016-03-28T05:15:16.459Z","updated_at":"2016-03-28T05:15:16.459Z"},"instance_options":{},"root":null,"scope":null}' - '{"object":{"id":37,"email":"beryl_keler@wiza.biz","created_at":"2016-03-28T05:15:17.624Z","updated_at":"2016-03-28T05:15:17.624Z"},"instance_options":{},"root":null,"scope":null}' - '{"object":{"id":5,"email":"wilhelmine_buckridge@crona.io","created_at":"2016-03-28T05:15:15.139Z","updated_at":"2016-03-28T05:15:15.139Z"},"instance_options":{},"root":null,"scope":null}' - '{"object":{"id":14,"email":"edward_wisoky@corkery.net","created_at":"2016-03-28T05:15:15.838Z","updated_at":"2016-03-28T05:15:15.838Z"},"instance_options":{},"root":null,"scope":null}' - '{"object":{"id":27,"email":"leonor@jerde.biz","created_at":"2016-03-28T05:15:16.848Z","updated_at":"2016-03-28T05:15:16.848Z"},"instance_options":{},"root":null,"scope":null}' - '{"object":{"id":2,"email":"carley@wyman.net","created_at":"2016-03-28T05:15:14.873Z","updated_at":"2016-03-28T05:15:14.873Z"},"instance_options":{},"root":null,"scope":null}' - '{"object":{"id":10,"email":"ervin.gleichner@cremin.org","created_at":"2016-03-28T05:15:15.527Z","updated_at":"2016-03-28T05:15:15.527Z"},"instance_options":{},"root":null,"scope":null}' - '{"object":{"id":15,"email":"lonzo.dickens@johnscole.name","created_at":"2016-03-28T05:15:15.916Z","updated_at":"2016-03-28T05:15:15.916Z"},"instance_options":{},"root":null,"scope":null}'
In the first debug, I serialize only one object, and in the second I try to do this for an array of objects. The first debug correctly returns the serialized version of the object (in json_api format), and the second debug is missing. I also tried ArraySerializer, without success: ActiveModel::Serializer::ArraySerializer.new(@admins, each_serializer: AdminSerializer).as_json how to achieve the desired serialization. Moreover, if this is achieved, can I use another simplified version of this? Because this debug statement is too verbose.
Tried all the solutions mentioned here - How do you initialize the ActiveModel :: Serializer class with an ActiveRecord :: Relation array?
The main problem I'm trying to solve is that in the Admin controller index method, the Admin object is passed as PORO to the index.html file. But I want a serialized version of json of this object so that I can pass it to my reaction components as prop
index method returns correct json when shooting http://dashboard.localhost.com {000/ admins.json 
UPDATE # 1 for the index method
def index @search = Admin.search(params[:q]) @admins_array = @search.result(:distinct => true).to_a if params[:page] @admins = @search.result(:distinct => true).page(params[:page][:number]).per(10) @admins_json_array = Kaminari.paginate_array(@admins_array).page(params[:page][:number]).per(10) else @admins = @search.result(:distinct => true).page(1).per(10) @admins_json_array = Kaminari.paginate_array(@admins_array).page(1).per(10) end @admins_json = ActiveModel::SerializableResource.new(@admins_json_array.to_a) ... ... ... end