B
B
Bogdan2017-07-27 13:18:07
Ruby on Rails
Bogdan, 2017-07-27 13:18:07

Rails JSON include in top level?

Hello. Is it possible to make an include like in the example?

menu_requirement.to_json(
        only: [ :number ],
        include: { institution: { only: :name } } )

The output is this:
{
    "number": "KL-000000053",
    "institution": {
        "name": "18 (ДОУ)"
    }
}

but need one
{
    "number": "KL-000000053",
    "institution_name": "18 (ДОУ)"
    }
}

Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Mirilaczvili, 2017-07-27
@2ord

as_json documentation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question