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...
12:42 did it for me!
Thank you very much
FYI - Turbo.visit(this.element.getAttribute('href'), { action: 'replace' }); is better than element.click if you use anchor tags sometimes in the redirect link
Useful, thanks
Thanks 👍
Thanks for this
Unfortunately in this approach, you are losing the flash message.
Actually you can!
Here's how:
flash[:notice] = "Comment created."
flash.keep(:notice)