Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to output all attributes jbuilder, without having to specify them all?

I'm using json to store document versions of my data in postgresql. I would like to output an entire tree of objects with children, children of children etc and all attributes. If any attributes are added to any of the objects at a later date, I would like them to be include in subsequent json.

Is there any way to output the entire contents without having to least each and every attribute? ie not like this:

json.(object_name, :id, :attr1, :attr2.... etc)
like image 318
riley Avatar asked Dec 26 '22 22:12

riley


1 Answers

I know this is an old thread, but I was wondering the same thing, and ended up here. Then I found a great answer here => How to extract all attributes with Rails Jbuilder?

@uiureo suggests to use json.merge!, and that worked perfactly for me :)

json.merge! object_name.attributes
like image 132
Hilde Avatar answered May 15 '23 10:05

Hilde