我试图形成一个看起来像这样的json响应:
{
"user": {
"birthday": "2013-03-13",
"email": "example@example",
"id": 1,
"name": null,
"username": "example"
},
"other_data": "foo"
}
Run Code Online (Sandbox Code Playgroud)
之前,当我刚回到用户时,我用过
render :json => @user, :except => [:hashed_password, :created_at, :updated_at]
Run Code Online (Sandbox Code Playgroud)
保持hashed_password,created_at和updated_at属性不被发送.有没有办法做到这一点,但也允许与用户一起发送其他数据?现在我只是逐个添加我想要发送到哈希的属性,但这显然不太理想.