json.data(search: params['bzq'])
json.header do
...
end
json.messages do
json.array! @messages do |msg|
json.body msg.body
end
end
end
Long-polling
You can use a combination of Rails renderers, ActionCable, PropsTemplate fragments, and preloading to stream updates to your users without much effort.
For example, if you already have an ActionCable channel setup, simply render the props and send the rendered node over the wire:
# index.json.props
json.data(search: params[:bzq]) do
json.posts do
json.array! @posts, partial: ['post', fragment: true] do
end
end
end