Mongoid: show entire mongodb object with embeded_in objects in Rails console
class Parent
  include Mongoid::Document
  embeds_many :children
  field :title
end
class Child
  include Mongoid::Document
  embedded_in :parent
  field :name
end
Rails console
parent = Parent.new(:title => "Hello World")
parent.children << Child.new(:name => "Pedro")
parent
#=> #<Parent _id: 4e2330开发者_运维问答286254cc0e7d000007, _type: nil, title: "Hellow World">
So how can I inspect entire object in Rails console, till children are embeded in my parent like I can do it in mogodb console
{
  "_id" : ObjectId("4e2330286254cc0e7d000007"),
  "title": "Hello World",
  "children" : [
    {
      "_id" : ObjectId("4d3ed089fb60ab534684b7e0"),
      "name" : "Pedro"
    }
  ]
}
You can try to inspect the attributes of your Mongoid object like so:
parent.attributes.inspect
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论