I have simple jbuilder view
json.id pharmaceutic.id
json.name pharmaceutic.name
json.dosage pharmaceutic.dosage.name
When pharmaceutic.dosage => nil
My rendered json looks like below:
{"id":1,"name":"HerzASS ratiopharm","dosage":null}
I would like set up for all jBuilder views that when some attribute is nil
it should be rendered as empty string.
{"id":1,"name":"HerzASS ratiopharm","dosage":""}
How to achieve that?
nil.to_s #=> ""
so, you can simply add .to_s
json.id pharmaceutic.id
json.name pharmaceutic.name.to_s
json.dosage pharmaceutic.dosage.name.to_s
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With