render_turbo_stream 4.3.4 → 4.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/lib/render_turbo_stream/controller_helpers.rb +14 -2
- data/lib/render_turbo_stream/libs.rb +1 -1
- data/lib/render_turbo_stream/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd429fcf5885a88fd9362d97a3af9c7cca947d173911b4552e16ef752edfc93a
|
4
|
+
data.tar.gz: 1070b77583f60c208f1f38f9b7b6963d4604710fcb8bba0dd2746c379ce47739
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7be3a88170fb10070ddee8cb81670c5684949961214dd855e724c1cabe9004615fbb2c64fadb3f3339f23a776b623d1c2d14efdd07c67557d647951797684db6
|
7
|
+
data.tar.gz: d303cf736a91ebb95d35a06023d487d1073f2fed926c5bf0e5a72ec4b29cd5a2cbc4d928a0df83364157d951ed9727cf6181f5425f69cf85b079cd4eb58e11c4
|
data/README.md
CHANGED
@@ -109,7 +109,7 @@ The Rails team has integrated `ActionCable` as `Turbo::StreamsChannel` into `Tur
|
|
109
109
|
|
110
110
|
```ruby
|
111
111
|
|
112
|
-
def
|
112
|
+
def create
|
113
113
|
turbo_stream_save(
|
114
114
|
@article.update(article_params),
|
115
115
|
if_success_redirect_to: articles_path,
|
@@ -118,6 +118,8 @@ def update
|
|
118
118
|
end
|
119
119
|
```
|
120
120
|
|
121
|
+
Note that if you want to redirect to show path, but the save action fails, `article_path(@article)` would throw an error. For this, the arguments `if_success_turbo_redirect_to` and `if_success_redirect_to` accept procs that are evaluated only on success. So your line would look like this `if_success_redirect_to: ->{article_path(@article)}`.
|
122
|
+
|
121
123
|
Assuming we want to build a form that works within a turbo-frame, including flash messages and redirects, we have to build all that inside a `turbo-frame`, and, within that we need a target-id, that must not be a turbo-frame. For that, there is a helper:
|
122
124
|
|
123
125
|
```haml
|
@@ -82,15 +82,23 @@ module RenderTurboStream
|
|
82
82
|
Rails.logger.debug(" • Successful saved && Redirect by «turbo_redirect_to»")
|
83
83
|
Rails.logger.debug(" • Set flash[:alert] => #{flashes[:alerts]}") if flashes[:alerts].present?
|
84
84
|
Rails.logger.debug(" • Set flash[:notice] => #{flashes[:notices]}") if flashes[:notices].present?
|
85
|
+
|
86
|
+
if if_success_turbo_redirect_to.is_a?(Proc)
|
87
|
+
redirect_path = if_success_turbo_redirect_to.call
|
88
|
+
else
|
89
|
+
redirect_path = if_success_turbo_redirect_to
|
90
|
+
end
|
91
|
+
|
85
92
|
render_turbo_stream([
|
86
93
|
[
|
87
94
|
:redirect_to,
|
88
|
-
|
95
|
+
redirect_path
|
89
96
|
]
|
90
97
|
])
|
91
98
|
|
92
99
|
elsif save_action && if_success_redirect_to.present?
|
93
100
|
response.status = 303
|
101
|
+
|
94
102
|
if allow_channel
|
95
103
|
Rails.logger.debug(" • Send actions through Turbo::StreamsChannel")
|
96
104
|
c_libs = RenderTurboStream::ChannelLibs.new(response)
|
@@ -103,7 +111,11 @@ module RenderTurboStream
|
|
103
111
|
Rails.logger.debug(" • Set flash[:notice] => #{flashes[:notices]}") if flashes[:notices].present?
|
104
112
|
Rails.logger.debug(" • Could not send #{streams.length} actions => #{streams}")
|
105
113
|
end
|
106
|
-
|
114
|
+
if if_success_redirect_to.is_a?(Proc)
|
115
|
+
redirect_to if_success_redirect_to.call
|
116
|
+
else
|
117
|
+
redirect_to if_success_redirect_to
|
118
|
+
end
|
107
119
|
|
108
120
|
else
|
109
121
|
Rails.logger.debug(" • Respond by TurboStream in #{streams.length} #{'action'.pluralize(streams.length)}")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: render_turbo_stream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.3.
|
4
|
+
version: 4.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- christian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06-
|
11
|
+
date: 2023-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|