本文介绍了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
发布评论