top of page

I still need to understand about turbo8




I received the announcement about Turbo8 in Ruby on Rails in my e-mail. It's in version beta, but we can use it. I searched about it, and I still have some doubts about whether I'll use turbo-streams in the actions of my controllers.

I'll try to explain why I am still using stimulus_reflex and why I'm not using turbo_actions in my controllers:

The turbo_streams or turbo_frames give real-time actions to the users. When you use these with stimulus_reflex, you can call some action in reflex class, and there, you can update multiple places using turbo. So, if you call the turbo in the controller, the action will reflect on the page. I'll try to explain with this approach:

Let's say you have a button to add a comment in a post; when this occurs, it will append to the current page, but let's say you need to inform in another view the number of comments in the application and, in another view the when occurs the last comment. How do you solve this using just the turbo_stream.html.erb?

Sorry, but I am still using the stimulus_reflex to solve this. Why? Because when I dispatch the action using stimulus_reflex, I can save the comment in the method of reflex class, and there are multiple triggers like:

post = Post.find(element.dataset.post_id) # here you can use current_user or something like that

comment = post.comments.build(comments_params) # you have here the same params.require that exists in the controllers

Turbo::StreamsChannel.broadcast_append_to post, target: "comments", partial: "comments/comment", locals: { comment: comment } 

Turbo::StreamsChannel.broadcast_update_to "comments_count", target: "comments_count", partial: 'comments/comments_count'

Turbo::StreamsChannel.broadcast_update_to "last_comment_stream", target: "last_comment_stream", partial: 'comments/last_comment_was', locals: {comment: comment}

Posts recentes

Ver tudo
Captura de tela de 2024-01-01 22-06-25.png

Hi, I'm Rodrigo Toledo

A full-stack developer skilled in both front-end and back-end development, building and maintaining web applications

  • Facebook
  • Youtube
  • LinkedIn
  • Instagram

I don't know everything, help me

Every day, I try to improve what I know about frameworks, and when this occurs, I'll try to share it with the community. Every day, I try to improve my knowledge about frameworks. When this happens, I will try to share it with the community.

Subscribe

Thanks for submitting!

bottom of page