`
luoping0425
  • 浏览: 108821 次
  • 性别: Icon_minigender_2
  • 来自: 赣州
文章分类
社区版块
存档分类
最新评论

rails to_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关系的对象

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics