假设你想要
records = Model.all records.to_a.map{|m| m.serializable_hash(:root => true)}
就像to_json(:root => true)一样
[ { "model": { "attribute_1": "value_1","attribute_2": "value_2",} } ... ]
解决方法
as_json
records.as_json(:root => true)
serializable_hash
records.to_a.map() {|x| { x.class.model_name.element => x.serializable_hash() } }
但这不适用于嵌套对象