I have some existing projects that were built upon a deprecated PHP framework, and I'm hoping to move them over to Ruby on Rails with minimal effort. My main problem right now is the format that the JSON is coming back in. My frontend code (all ExtJS) is expecting JSON in the format:
{
"result": [
[id: 1, name: "mike"],
[id: 2, name: "john"],
[id: 3, name: "gary"]
]
}
But the default return from Ruby on Rails is as follows:
{
"result": [
{"record" : {id: 1, name: "mike"}},
{"record" : {id: 2, name: "john"}},
{"record" : {id: 3, name: "gary"}}
]
}
My controller is basically doing nothing but:
@records = Record.find(:all)
respond_to do |format|
format.json { render :text => @records.to_json}
end
As you can see, it's adding in an additional key to every record, which my frontend ExtJS code is not capable of parsing as-is. Is there any way to stop this from occuring?
Thanks for any help you can offer,
Mike Trpcic