How to nest another value inside a nested objectin Jbuilder in Rails/Ruby

Viewed 24

Here's my jbuilder file:

json.actor_avatar_url notification.actor.avatar.blob.service_url if notification.actor.avatar.attached?
json.actor notification.actor

Which gets me this output:

{
 "actor_avatar_url": "http://res.imageurl.com/testimage/etc",
 "actor": {
            "id": 151,
            "allow_password_change": false,
            "username": "test test",
            "email": "test4@test.com",
            "created_at": "2021-03-27T17:52:08.866Z",
            "updated_at": "2021-04-06T22:56:26.845Z",
            }
}

But I want to get this output:

{
 "actor": {
            "actor_avatar_url": "http://res.imageurl.com/testimage/etc",
            "id": 151,
            "allow_password_change": false,
            "username": "test test",
            "email": "test4@test.com",
            "created_at": "2021-03-27T17:52:08.866Z",
            "updated_at": "2021-04-06T22:56:26.845Z",
            },
}

With the avatar_url somehow placed inside of the nested object.

But this of course doesn't work:

json.actor do
    notification.actor
    json.actor_avatar_url notification.actor.avatar.blob.service_url if notification.actor.avatar.attached?
end

How would I accomplish this?

Thanks!

0 Answers
Related