Conversation
| flash.now[:notice] = "Item has been updated" | ||
| render partial: "update", locals: {item}, content_type: "text/vnd.turbo-stream.html" |
There was a problem hiding this comment.
| flash.now[:notice] = "Item has been updated" | |
| render partial: "update", locals: {item}, content_type: "text/vnd.turbo-stream.html" | |
| respond_to do |format| | |
| format.turbo_stream do | |
| render partial: "update", locals: {item} | |
| end | |
| format.html do | |
| flash[:notice] = "Item has been updated" | |
| redirect_to workspace | |
| end | |
| end |
Untested! But I think this addresses the I found that Turbo expects HTTP response to have the
confusion in your (great!) article. See the text/vnd.turbo-stream.html content type in order to activate stream elementsTurbo::StreamsHelper documentation for more.
There was a problem hiding this comment.
I was thinking of this section in particular:

The preferred way to respond with Turbo Streams in Rails is with implicit .turbo_stream.erb templates (e.g. 860c706) and/or format.turbo_stream { … } (in respond_to) blocks. They set the custom response content type automatically.
There was a problem hiding this comment.
Will it work without respond_to? I mean: render turbo_stream: "update", locals: ....
| end | ||
| end | ||
| flash.now[:notice] = "Item has been deleted" | ||
| render partial: "update", locals: {item}, content_type: "text/vnd.turbo-stream.html" |
There was a problem hiding this comment.
Does locals: {item} expand to locals: {item: item} somehow or is this a JavaScript-brain typo?
There was a problem hiding this comment.
Does
locals: {item}expand tolocals: {item: item}somehow or is this a JavaScript-brain typo?
That's right, @javan. In ES6, there's a shorthand version for properties with a value coming from a variable with the same name. So, having { item } will is the same as writing { item: item }
There was a problem hiding this comment.
Does locals: {item} expand to locals: {item: item} somehow
Yes, via Ruby Next 🙂
It's a proposed feature: https://bugs.ruby-lang.org/issues/15236
0f9a0b6 to
f311544
Compare
2e4efd0 to
7b2111f
Compare
Hotwire allows use to leverage HTML-over-the-Wire as much as possible and get rid of unnecessary JavaScript.
What's in a poke