I am working with rails API , and I want to render JSON file but with specific way. I have a model with named Store, and in this model, i have records like State and City. My problem is that I want render JSON to looks like this:
{
"Arizona": [
"Phoenix",
"Tucson"
],
"California": [
"Anaheim",
"Los Angeles",
"San Diego",
"San Francisco"
],
"Colorado": [
"Denver"
],
}
I may have in model many records with the name Colorado or with the name California, but every California record have its own city name, for example:
this is my model
| state | city |
-----------------------
|California| Anaheim |
|Colorado | Denver |
|California| San Diego|
and so on ..
so I want to pair every city that belongs to the unique state, so my JSON would show only one time the State name .
any suggestion?