hotwired/turbo-rails

Inverted parameters in stream responses

letItCurl opened this issue ยท 2 comments

Hey everyone ๐Ÿ‘‹

This:

<%= turbo_stream.update_all [@chat, :edit], @chat %>

Renders this:


<turbo-stream action="update" targets="#edit_chat_f5623fd8-6889-492f-a848-35740d3a83ef">
      ....
</turbo-stream>

The thing that tripped me is that this line turbo_stream.update_all [@chat, :edit], @chat render dom_id(:edit, @chat).
Which is inverted...

Is that intented?

I think there is a confusion here.

The second argument to dom_id is a prefix, dom_id(:edit, @chat) is invalid and will raise an exception.

Turbo targets are rendered using the logic of dom_id so [@chat, :edit] is similar to dom_id(@chat, :edit) which will return "edit_chat_xxxx" where :edit is correctly used as a prefix. If you use dom_id in your view, you can use the same arguments in the same order in your targets.

You are right I got confused I think!!

thank you for spending time on this :)