Advice on rendering JSON in a controller when multiple things need to be rendered #254
-
Currently I have controllers rendering multiple things from an action for example
I am currently utilizing the serializable_hash method and that seems to work fine, but it was pointed out to me that JSON to a hash and then back to json is taxing so I'm switching to serialize instead. The problem is since serialize produces raw json the above bit of code no longer works. I have a current implementation working for this
But I wanted advice if there is a better way on going about doing this And also as a side question what is the most performant method between serialize and serializable_hash? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
@Sheikh-TDH Does
|
Beta Was this translation helpful? Give feedback.
Now I think your current solution using
serializable_hash
would be good enough.serializable_hash
just returns a Hash so there is not cost of converting objects into a JSON. You can build a Hash with multiple Hashes some of which are built byserializable_hash
and then convert it to JSON only once.