Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 988
Mio Avatar asked Dec 09 '25 18:12

Mio


1 Answers

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
like image 72
Mio Avatar answered Dec 11 '25 12:12

Mio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!