除外:Railsのモデル、私はこのようになりますJSONレスポンスを形成しようとしています属性
{
"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属性の送信を抑止します。これを行う方法はありますか?また、ユーザーと一緒に追加のデータを送信することもできますか?今は、ハッシュに送る属性を1つずつ追加するだけですが、これは明らかに理想的ではありません。
正確に私が探していたもの、ありがとう –