2 years ago

#64254

test-img

Jerome

Rails console destroy action but is not percolated to the application and handling via turbo stream

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?

hotwire-rails

ruby-on-rails-7

turbo

0 Answers

Your Answer

Accepted video resources