action cable

Anonymous
ruby
11/29/2023 5:36 PM
560 B
20
Indexable
class CommentsChannel < ApplicationCable::Channel
  def subscribed
    stream_for @question
  end
end


class QuestionsController < ApplicationController
  .....
    
  def publish_comment
    return if @comment.errors.any?
    
    CommentsChannel.broadcast_to(
      @question,
      ApplicationController.render(
        partial: 'comments/show',
        locals: { comment: @comment }
      )
    )
  end
  .....
end
Editor is loading...
Leave a Comment