I'm new in Rails and I use the version 4.2.0.
Let's suppose that we have the following JSON at the url localhost:3000/users
[{id: 1, "firstName": "John","lastName": "Smith"},
{id: 2, "firstName": "John","lastName": "Red"}]
but this is not what I want, I expect something like:
{ users :[
{id: 1, "firstName": "John","lastName": "Smith"},
{id: 2, "firstName": "John","lastName": "Red"}
]}
How can i do? Thanks everybody.
try this in users index controller
render json: {users: @users}
where
@users = [{id: 1, "firstName": "John","lastName": "Smith"},
{id: 2, "firstName": "John","lastName": "Red"}]
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