我试图形成一个JSON响应,看起来像这样:Rails的模型散列,排除属性
{
"user": {
"birthday": "2013-03-13",
"email": "[email protected]",
"id": 1,
"name": null,
"username": "example"
},
"other_data": "foo"
}
之前,当我刚回国的用户,我用
render :json => @user, :except => [:hashed_password, :created_at, :updated_at]
到保持发送hashed_password,created_at和updated_at属性。有没有办法做到这一点,但也允许额外的数据与用户一起发送?现在,我只是将我想要发送给哈希的属性逐个添加,但显然这并不理想。
正是我在找什么,谢谢一吨 – 2013-03-13 22:37:57