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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de051d73d56102cedd1c2a29e0794041dbe3cd18577300002005ac050eb085e4
4
- data.tar.gz: 0224b8f893ecb5408f917b4fe201650b54a815bab020fc3a549cc869da9615a6
3
+ metadata.gz: dd429fcf5885a88fd9362d97a3af9c7cca947d173911b4552e16ef752edfc93a
4
+ data.tar.gz: 1070b77583f60c208f1f38f9b7b6963d4604710fcb8bba0dd2746c379ce47739
5
5
  SHA512:
6
- metadata.gz: f756884588c93fcf1052cfcb358fb69e7d996b746aa79d8cf3b134a91037e6acc3ea34253184491b3383a79bf87c2e8b046a4b67b70db950bb1182e41f8c49ca
7
- data.tar.gz: 23bcf3db97515ace21d9f84fde860941326db0001c9388e44cb152a08f6288c64e72e949d884fd9be9f06ba3fc8cfe4a2ce9231f877ecc0c8536642e228c65b5
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 update
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
- if_success_turbo_redirect_to
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
- redirect_to if_success_redirect_to
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)}")
@@ -69,7 +69,7 @@ module RenderTurboStream
69
69
  ['new', _id.class.to_s.downcase]
70
70
  ).join('-')
71
71
  else
72
- raise("target_id / argument ID: Only String or object with method :id accepted")
72
+ _id.to_s
73
73
  end
74
74
  end +
75
75
  [
@@ -1,3 +1,3 @@
1
1
  module RenderTurboStream
2
- VERSION = "4.3.4"
2
+ VERSION = "4.3.5"
3
3
  end
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
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-17 00:00:00.000000000 Z
11
+ date: 2023-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails