Anders

Joined

1,360 Experience
13 Lessons Completed
0 Questions Solved

Activity

Posted in Turbo stream problem

Thank you for your reply...

I was under the impression that

broadcasts

would be enough. But that doesn't include create I guess.

ActionCable seems like a hassle to set up. Thought turbo could do this.
I'll just add some javascript 🫣 to handle some kind of fetch new function

Posted in Turbo stream problem

Hello...

I'm having a problem with a view not fully auto-updating using turbo.
It currently only works when updating or destroying.

So to keep it kinda short, I have a site where users can crud some products. On an office screen, products are listed. All updates shows up automatically. Newly created products can only be loaded if this view is refreshed.

The product.rb simply uses

broadcasts

The route has

resources :products
get "screen", to: "products#screen"

The new and edit templates doesn't use turbo. And the product_controller simply does something like:

def create
        @product = Product.new(product_params)
        if @product.save
            redirect_to products_path
        else
            render :new
        end
 end

In the products_controller I also define the 'screen'

def screen
        @products = Product.all
end

And on the views/products/screen.html.erb I do

<% @products.each do |product| %>
  <%= turbo_stream_from product %>
  <%= render partial: "product", locals: { product: product } %>
<% end %>

and the views/products/_product.html.erb

<div id="<%= dom_id product%>">
  <%= product_name %>
</div>

What am I missing?
Thank you