简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM