0

A form contains a destroy button

<%= button_to 'bomb', message, method: :delete, form: { data: { turbo_confirm: 'R U sure?' } } %>

and the controller responds in an expected manner

    respond_to do |format|
      format.turbo_stream

[logging: ]

[ActionCable] Broadcasting to Z2lkOi8vc2V2ZW4vUm9vbS8x: "<turbo-stream action=\"remove\" target=\"message_12\"></turbo-stream>"

However, in the console:

> Message.last.destroy

  Message Destroy (0.4ms)  DELETE FROM "messages" WHERE "messages"."id" = $1  [["id", 15]]
  TRANSACTION (6.0ms)  COMMIT
  Room Load (0.6ms)  SELECT "rooms".* FROM "rooms" WHERE "rooms"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
[ActionCable] Broadcasting to Z2lkOi8vc2V2ZW4vUm9vbS8x: "<turbo-stream action=\"remove\" target=\"message_15\"></turbo-stream>"

=>
#<Message:0x000000010fcc9da8
 id: 15,
 room_id: 1,
 content: "and this?",
 created_at: [...]
 updated_at: [...]

does not affect the browser and in fact nothing is registered in the log. Refreshing the browser does reset things as per databse objects.

This is running rails 7.0.1 and ruby 3.1.0.

What is wrong that generates this unepected behaviour?

Jerome
  • 5,583
  • 3
  • 33
  • 76
  • It seems like both the turbo_stream response from the controller and a broadcast from the model are triggered. Do you have any broadcast method in your `Message` model? – Thomas Van Holder Feb 09 '22 at 13:53
  • Are you insert ***turbo_stream_from*** in your remove page? If not, it can not update instantly. And you can check whether your target dom_id is correct? – KennetsuR Feb 18 '22 at 10:15
  • You have to set Redis See https://stackoverflow.com/questions/71141502/rails-turbo-stream-broadcast-not-updating-view – Maria Ruy Feb 08 '23 at 04:36

0 Answers0