If the cart is empty I’m displaying zero until page refresh, how can I turbo_stream.update a blank instead? turbo_stream.update(‘cart_counter’, @cart_counter)
I’m not sure I understand what you’re asking, but what about filling @cart_counter
with ''
?
That didn’t work I assume because it was in a ternary with a different data type, integer
@cart_counter = @cart.orderables.count > 0 ? @cart.orderables.count : " "
respond_to do |format|
format.turbo_stream do
render turbo_stream: [turbo_stream.replace('cart',
partial: 'cart/cart',
locals: { cart: @cart }),
turbo_stream.update('cart_counter', @cart_counter)
]
end
end
The code you show sets @cart_counter
to a string with a space in it correctly. Confirm it yourself with a debugger on the respond_to line.
What is the exact problem you’re having here? Maybe I don’t understand what you’re trying to achieve.