rails to_json的使用_Ruby_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > Ruby > rails to_json的使用

rails to_json的使用

 2011/1/18 8:04:41  luoping0425  http://luoping0425.javaeye.com  我要评论(0)
  • 摘要:http://apidock.com/rails/ActiveRecord/Serialization/to_jsonkonata.to_json(:include=>:posts)#=>{"id":1,"name":"KonataIzumi","age":16,"created_at":"2006/08/01","awesome":true,"posts":[{"id":1,"author_id":1,"title":"Welcometotheweblog"},{"id":2
  • 标签:使用 rails JSON

http://apidock.com/rails/ActiveRecord/Serialization/to_json

?

konata.to_json(:include => :posts)
  # => {"id": 1, "name": "Konata Izumi", "age": 16,
        "created_at": "2006/08/01", "awesome": true,
        "posts": [{"id": 1, "author_id": 1, "title": "Welcome to the weblog"},
                  {"id": 2, author_id: 1, "title": "So I was thinking"}]}

使用include包含有one_to_many关系的对象

上一篇: relationship with 下一篇: ROR开发环境搭建
发表评论
用户名: 匿名