mercredi 6 septembre 2017

How to modify the response of as_json in ruby on rails?

I have a model called Event, which in turn has_one association with EventType

event = Event.last

event.as_json(include: {event_type: {only: :name}}, only: :event_type)

This is giving me output

{ :event_type=> { "name"=>"Chat" } }

But my desired response is

{ :event_type => "Chat" }

How can I achieve this?

Aucun commentaire:

Enregistrer un commentaire