0

I have a Rails 6 View with three numerical integer indicators: speed, temperature and pressure. These values ​​are stored in SavedObject model as serialized objects. And in the controller are passed to the view with their respective instance variables. @speed @temperature @pressure

The question

How can I send a separate broadcast (with turbo hotwire) for each serialized object update, conditioned by the "name" column (like "Device 2 Temperature") , so each broadcast reach to their own partial? (there are three different partials in the same view)

This is the model

class SavedObject < ApplicationRecord
    serialize :value
end

These are the columns.

      t.string :name
      t.text :value

Record Example

#<SavedObject:0x000055a2f6f34fa0
id: 144,
name: "Device 2 Temperature",
value: [{last_value: "52", equip_id: 2}]
lcchatter
  • 41
  • 2
  • 7

1 Answers1

0

So this would be using the hotwire-rails gem that uses action cable to make an integration with Hotwire. Just FYI this is not a part of hotwire directly it integrates it with websockets thats why there is a lack of visual documentation it is all in the code. Okay now that is out of the way...

It is definitely possible to do this and it would be just changing the logic in ruby you could add a callback method and that is where you could check what kind of object it is and render the correct partial. I would use the same stream name for all of them for simplicity and broadcast different partials to that stream based on the object.

yungindigo
  • 241
  • 1
  • 6