You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm just trying to render only the @messages = @room.messages.last(10), after a new message is created.
I tried 4 different ways, because I did not understand how to do it.
What I did is to render all messages after format.turbo_stream in messages_controller.rb, so in app/views/messages/create.turbo_stream.slim it looks like (I use Slim templates...):
And on sender side it works, and I see only the last 10 messages. But, because Messagebroadcasts_to :room, it will use append on the receiver side and each receiver see then 10 older messages and each appended one.
How can I use broadcasts_to :room or after_create_commit -> { broadcast_append_to room } respectively to broadcasts only last 10 messages for each room?
It should be possible to do this, right?
The text was updated successfully, but these errors were encountered:
I just found out, in order to show the last 10 messages on sender side I could do in MessagesController this:
In create action just remove format.turbo_stream (and if you wish remove app/views/messages/create.turbo_stream.erb too) and it is working.
Also, no need for app/assets/javascripts/controllers/form_controller.js and data in app/views/messages/_form.html.slim.
I'm just trying to
render
only the@messages = @room.messages.last(10)
, after a new message is created.I tried 4 different ways, because I did not understand how to do it.
What I did is to render all messages after
format.turbo_stream
inmessages_controller.rb
, so inapp/views/messages/create.turbo_stream.slim
it looks like (I use Slim templates...):And on sender side it works, and I see only the last 10
messages
. But, becauseMessage
broadcasts_to :room
, it will useappend
on the receiver side and each receiver see then 10 older messages and each appended one.How can I use
broadcasts_to :room
orafter_create_commit -> { broadcast_append_to room }
respectively to broadcasts only last 10 messages for each room?It should be possible to do this, right?
The text was updated successfully, but these errors were encountered: