0

I'm working on a rails 7 app with hotwire. I have a form modal, when subimited, turbo should remove html from modal and show flash message.

When i put my turbo code in my controller i works:

# emails_controller.rb
  def forward
    service = Email::Forward.new(
      recipients: params[:recipients].split(','),
      sender: current_user.email,
      html: params[:html_to_forward]
    ).call

    if service.errors.empty?
      flash.now[:success] = t('.success')
    else
      flash.now[:error] = t('.error')
    end

    respond_to do |format|
      format.turbo_stream do
        render turbo_stream: [
          turbo_stream.update('forward_modal', ''),
          turbo_stream.update('flash', partial: 'shared/flash', locals: { flash: flash })
        ]
      end
    end

But when i try to put the same code in a forward.turbo_stream.slim view, it do nothing, and i have no error message.

# views/emails/forward.turbo_stream.rb
= turbo_stream.update('forward_modal', '')
= turbo_stream.update('flash', partial: 'shared/flash', locals: { flash: flash })

Any idea about what is happening ?

Sonfaya
  • 27
  • 6

1 Answers1

0

Maybe a typo... but your code references the file as "views/emails/forward.turbo_stream.rb", but should probably be "views/emails/forward.turbo_stream.slim"? Or perhaps you have both files and have the good code only in the bad file? I've made similar mistakes with "action.html.slim" vs. "action.turbo_stream.slim". Taking a while to get used to the new naming convention.

unrared
  • 93
  • 1
  • 4