1

In my controller, i have two methods that render a json, i want to use differents serializer for each method. how can i do it. i've tried : render json: response ,each_serialiser: SerializerName in every methods by it's doesn't work

Maryeme Alaoui
  • 93
  • 2
  • 13
  • Possible duplicate of [How to implement multiple different serializers for same model using ActiveModel::Serializers?](http://stackoverflow.com/questions/12485404/how-to-implement-multiple-different-serializers-for-same-model-using-activemodel) – Saravanabalagi Ramachandran Nov 28 '16 at 07:40

2 Answers2

0
render json: @response, serializer: SerializerName

should do the trick.

Viktor
  • 2,623
  • 3
  • 19
  • 28
nbirla
  • 600
  • 3
  • 14
  • Did you add "include ActiveModel::Serializers::JSON" in the model? – nbirla Sep 17 '14 at 18:46
  • no i didn't added this line, but when i don't specify which serializer, it works with calling the serializer that have the same name then the model. now i've added a new serializer with a different name and i want to call it for an other action. – Maryeme Alaoui Sep 17 '14 at 18:51
0

you should create two serializer for each response use one of them and rename the response.