jeudi 30 juin 2016

Set json attribute to nil within a jbuilder block

I have a scenario where I want to set a json attribute to nil if its object value is nil within a jbuilder block:

example of how I'm doing it now: unless obj.details.nil? json.details do |json| json.value1 obj.details.value1 json.value2 obj.details.value2 end else json.details nil end My question is is there a cleaner way to do this so I don't have to use an unless/else

Aucun commentaire:

Enregistrer un commentaire