Search code examples
ruby-on-railsactiverecordserializationhashactive-model-serializers

Hash to Active Model Serializer


I have a hash @branches that is basically:

{1 => 5}, {2 => 6}

Is it possible for me to send this to a serializer and get output json like so:

{ branch_id: 1, branch_name: 'Hello', count_5}

I've made a custom serializer and calling it like so:

render json: @branches, serializer: AvilableStockBranchSerializer

How can I pass the hash data to the serializer?


Solution

  • Why do you need AMS?

    You can use @branches.to_json instead