Let's say you have a model called Widget which includes :id
and :name
.
In your Widget#index endpoint, you want to render all widgets in json, however... you also want to include another value for each record that isn't apart of the model called foobar. So you want the end result to look like this...
{
"widgets": [
{
"id":, 1,
"name": "widgy",
"foobar": true
},
{
"id":, 2,
"name": "gadgy",
"foobar": false
}
]
}
How can you edit the following code to allow for something like this?
widgets = Widget.all
render json: widgets