我将如何在 rails 3.2 中将元数据添加到 json 响应中?有没有办法访问模型元数据并将其包括在内?IE。字段名称和数据类型。
类似于以下内容:
{
"metaData":{
"columns":[
{
"dataIndex":"id",
"text":"User ID",
"type":"integer"
},
{
"dataIndex":"name",
"text":"User Name",
"type":"string"
},
{
"dataIndex":"birthday",
"format":"dd-mmm-yy",
"text":"Birthday",
"type":"datetime"
}
]
},
"data":[
{
"id":1,
"name":"Queen Elizabeth",
"birthday":"1533-09-07T06:33:39Z"
},
{
"id":2,
"name":"Queen Elizabeth II",
"birthday":"1926-04-21T02:40:00Z"
}
]
}