假设我有这个短代码:
item = Item.find(params[:id])
render :json => item.to_json
但我需要向返回的 json 对象插入/推送额外信息,我该怎么做?
假设我需要插入这个额外的信息:
message : "it works"
谢谢。
最佳答案
item = Item.find(params[:id])
item["message"] = "it works"
render :json => item.to_json
关于ruby-on-rails - 如何在 ruby/rails 中将数据附加到 json?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3146980/