07/12/11 16:22:19
>>948
18 # konata.to_json(:only => [ :id, :name ])
19 #
20 # {"id": 1, "name": "Konata Izumi"}
-----------------------------------------------------------------------
36 # konata.to_json(:include => :posts)
37 #
38 # {"id": 1, "name": "Konata Izumi", "age": 16,
39 # "created_at": "2006/08/01", "awesome": true,
40 # "posts": [{"id": 1, "author_id": 1, "title": "Welcome to the weblog"},
41 # {"id": 2, author_id: 1, "title": "So I was thinking"}]}
-----------------------------------------------------------------------
45 # konata.to_json(:include => { :posts => {
46 # :include => { :comments => { :only => :body } },
48 # :only => :title } })
49 #
50 # {"id": 1, "name": "Konata Izumi", "age": 16,
51 # "created_at": "2006/08/01", "awesome": true,
52 # "posts": [{"comments": [{"body": "1st post!"}, {"body": "Second!"}],
53 # "title": "Welcome to the weblog"},
54 # {"comments": [{"body": "Don't think too hard"}],
55 # "title": "So I was thinking"}]}
言うほど悪くはないと思うぞ(サンプルコードとしては)
bodyがどこから出てくるのかいまいちよくわからん…むぅ公式ドキュメント…
URLリンク(caboo.se)