Turbo.remove() not working , while turbo.update still performed

550 views Asked by At

i'm building an app with rails 7 and hotwire.

I have a div with a invite message, when the invitation is declined, 2 actions should be triggered:

I- Update my flash messages to display 'you declined the invitation' in my toaster (Working) II- Remove the div containing the invitation.

There is no problem with my turbo_stream.update() for my flash, i got no error from. my remove(), but nothing happens, the message still here.

I try to use other methods, ie: replace() with and empty element, but still not working.

I'm quite confuse on why turbo ignore this instruction, any idea ?

The code:

my view:

div.mx-auto.company class='w-[860px]'
  - if current_user.pending_mailboxes_invitation.present?
    div.border.border-white.border-2.rounded-lg.p-10 id="invitation"
      p.profile-subtitle = "Vous avez été invité à rejoindre la boîte mail #{current_user.pending_mailboxes_invitation.mailbox.name}"
      p= "Si vous acceptez, la boîte mail sera ajoutée à votre liste et vous la retrouverez dans le projet #{current_user.pending_mailboxes_invitation.mailbox.project.name}"
      div.flex.my-3.gap-5.items-center
        = link_to 'Accepter', confirm_mailboxes_user_url(current_user.pending_mailboxes_invitation), data: { turbo_method: :put }, class: "btn btn-primary-dark"
        = link_to 'Décliner l\'invitation', mailboxes_user_url(current_user.pending_mailboxes_invitation), data: { turbo_method: :delete }
  hr/
# [...]

my controller

  def destroy
    @mailboxes_user.destroy
    flash.now[:success] = t('.success.invitation')

    respond_to do |format|
      format.turbo_stream
    end
  end

my destroy.turbo_stream.slim

= turbo_stream.remove('invitation')
= turbo_stream.update('flash', partial: 'shared/flash', locals: {flash: flash} )

Thanks for you time and help :)

1

There are 1 answers

0
Athira Kadampatta On

I suspect it is because the id "invitation" is not getting applied to the message div. Could you please try the following haml code and check again. It should work.

div.border.border-white.border-2.rounded-lg.p-10#invitation