Let's say you want to
records = Model.all
records.to_a.map{|m| m.serializable_hash(:root => true)}
just like to_json(:root => true)
does
[
{
"model": {
"attribute_1": "value_1",
"attribute_2": "value_2",
}
}
...
]
records.as_json(:root => true)
records.to_a.map() {|x|
{ x.class.model_name.element => x.serializable_hash() }
}
This will not work with nested objects though
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With