Ruby on Rails

Поделиться
HTML-код
  • Опубликовано: 13 июн 2024
  • How to redirect from a form that is inside a turbo frame?
    This is a very specific question that you will definitely have after working with Hotwire for some time.
    There are many possible solutions, some better that the others.
    Let's explore the problem and different strategies to solving it:
    1. add and click a hidden link
    2. new turbo stream redirect action
    3. adding turbo stream helpers and params
    0:00 Introduction
    0:49 Full page redirect does not work?
    4:00 Break out of turbo frame does not work?
    4:55 turbo stream hidden link
    10:50 do not cache hidden link
    12:42 Create a New Turbo Stream Action (best redirect)
    14:56 A Turbo Stream action with params (more complicated)
    19:50 Final demo
    Episode source code: github.com/corsego/151-dialog...
    Based on this blogpost: blog.corsego.com/custom-turbo...

Комментарии • 7

  • @kerlq3713
    @kerlq3713 Месяц назад

    12:42 did it for me!
    Thank you very much

    • @kevkevships
      @kevkevships 16 дней назад

      FYI - Turbo.visit(this.element.getAttribute('href'), { action: 'replace' }); is better than element.click if you use anchor tags sometimes in the redirect link

  • @remotronic
    @remotronic 6 месяцев назад +1

    Useful, thanks

  • @yaroslavbozhak9107
    @yaroslavbozhak9107 6 месяцев назад +1

    Thanks 👍

  • @njongefred
    @njongefred 6 месяцев назад

    Thanks for this

  • @mateuszbialowas
    @mateuszbialowas 6 месяцев назад +1

    Unfortunately in this approach, you are losing the flash message.

    • @SupeRails
      @SupeRails  6 месяцев назад +2

      Actually you can!
      Here's how:
      flash[:notice] = "Comment created."
      flash.keep(:notice)