如何将数据附加到ruby/rails中的json? [英] how to append data to json in ruby/rails?

查看:95
本文介绍了如何将数据附加到ruby/rails中的json?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有这个短代码:

item = Item.find(params[:id])
render :json => item.to_json

但是我需要向返回的json对象插入/推送额外的信息,我该怎么做?

but i needed to insert/push extra information to the returned json object, how do i do that?

让我说我需要插入以下额外信息:

Lets say i need to insert this extra info:

message : "it works"

谢谢.

推荐答案

item = Item.find(params[:id])
item["message"] = "it works"
render :json => item.to_json

这篇关于如何将数据附加到ruby/rails中的json?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆