Ruby on rails 使用Mongoid时,如何在json响应中包含根?
使用ActiveRecord似乎很容易:Ruby on rails 使用Mongoid时,如何在json响应中包含根?,ruby-on-rails,json,mongoid,Ruby On Rails,Json,Mongoid,使用ActiveRecord似乎很容易: config.active_record.include_root_in_json = true 但是我找不到合适的Mongoid文档以下是您需要的文档: 根据config/mongoid.yml中的文档,您只需设置: 将_root_包含在_json中:true 干杯以下是您需要的文档: 根据config/mongoid.yml中的文档,您只需设置: 将_root_包含在_json中:true Rails 4中的cheers在mongoid.y
config.active_record.include_root_in_json = true
但是我找不到合适的Mongoid文档以下是您需要的文档: 根据config/mongoid.yml中的文档,您只需设置: 将_root_包含在_json中:true
干杯以下是您需要的文档: 根据config/mongoid.yml中的文档,您只需设置: 将_root_包含在_json中:true
Rails 4中的cheers在mongoid.yml中使用include_root_in_json设置的jbuilder没有添加包装器。我更新了jbuilder模板,如下所示:
# wrap scaffolded template with set!
# people/index.json
json.set! :people do
json.array!(@people) do |p|
json.extract! p, :name, :age
end
end #=> returns {"people" : [ "name" : "Jane", "age" : 30 ] }
在Rails 4中,jbuilder在mongoid.yml中使用include_root_in_json设置时没有添加包装器。我更新了jbuilder模板,如下所示:
# wrap scaffolded template with set!
# people/index.json
json.set! :people do
json.array!(@people) do |p|
json.extract! p, :name, :age
end
end #=> returns {"people" : [ "name" : "Jane", "age" : 30 ] }