jb
jb copied to clipboard
Rendering partials inline requires #to_json
trafficstars
When calling rendering a partial a different template format, such as slim in my case, the render call needs to have #to_json called on it otherwise it returns a ruby hash instead of valid json. I didn't see any heads ups on this in the documentation so I'm not sure if this is intentional behavior or not.
For example, using jbuilder you can use something like this:
render partial: 'entry', object: @entry, formats: :json
whereas with jb you need this:
render(partial: 'entry', object: @entry, formats: :json).to_json
It is correct, because a .jb file returns a hash