Search code examples
ruby-on-railsjsonjbuilder

Render specific partial in a parent folder with jbuilder


I'm using jbuilder in my rails project.

On a route I can get the index of my devices or show a device with his id.

But a User have many Devices. So on the route users/:id/devices I would like to be able to get the devices. For the moment I have a partial called _device.json.jbuilder with the path app/views/api/v1/devices/_device.json.jbuilder. I would like to call it from app/views/api/v1/users/devices.json.jbuilder


Solution

  • The answer is to give the full path inside app/views. In that case :

    /api/v1/users/devices.json.jbuilder look like this

    json.partial! '/api/v1/devices/device', devices: @devices