现在我得到:如何在JBuilder中的默认返回空字符串,而不是“<null">
{"id":1,"name":"HerzASS ratiopharm","dosage":null}
我想回的""
代替null
但作为默认如何实现这一目标。我不希望添加m.dosage || ""
在我的应用程序的每个属性。
我保持我的JBuilder意见views/api/documents/_document.json.jbuilder
json.id document.id
json.category document.category # sometimes this is nil
json.note document.note
json.attachments document.attachments do |attachment|
json.url URI.join(request.url, attachment.url).to_s
end
json.created_at document.created_at
json.updated_at document.updated_at
我不明白,并在那里我应该把这个方法? – tomekfranek
就在你获得json数据之后。 – anand4tech