0

I have some code rendering json as follows...

        serialized = ActiveModel::ArraySerializer.new(actions, each_serializer: Api::V1::ActionSerializer)
        render json: { actions: serialized }

What I need... is to turn serialized into a string so I can store it in a database record. serialized.to_s does not work.

How can I turn this #<ActiveModel::ArraySerializer:0x007fdfddc332b8> into a string representation of the JSON?

chris P
  • 6,359
  • 11
  • 40
  • 84

1 Answers1

0

You can use ActiveSupport::JSON#encode to get the string representation of the JSON.

ActiveSupport::JSON.encode(serialized)
K M Rakibul Islam
  • 33,760
  • 12
  • 89
  • 110