Rails 3.1 include

编程入门 行业动态 更新时间:2024-10-27 22:29:46
本文介绍了Rails 3.1 include_root_in_json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

ActiveRecord::Base.include_root_in_json = true 在 rails 3.10.rc4 中似乎不起作用,我在文档中也没有看到.

既然根元素现在默认是关闭的,我们如何重新启用它?

@comments.to_json 在 rails 3.1 现在看起来像

[{评论:有趣的街头公园.",created_at: 2011-06-29T02:28:29Z,}]

在以前的版本中,它具有我需要取回的根节点.

[{评论: {评论:有趣的街头公园.",created_at: 2011-06-29T02:28:29Z}}]

解决方案

尝试直接在您的 Comment 模型上设置.

class 注释

ActiveRecord::Base.include_root_in_json = true doesn't seem to be working in rails 3.10.rc4 and I don't see it in the docs.

Since the root element is now off by default how do we re-enable it?

@comments.to_json in rails 3.1 now looks like

[ { comment: "Fun street park.", created_at: 2011-06-29T02:28:29Z, } ]

And in previous versions it has the root node which I need to get back.

[ { comment: { comment: "Fun street park.", created_at: 2011-06-29T02:28:29Z } } ]

解决方案

Try setting this directly on your Comment model.

class Comment < ActiveRecord::Base self.include_root_in_json = true end

更多推荐

Rails 3.1 include

本文发布于:2023-10-11 04:33:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1480697.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Rails   include

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!