action cable

mail@pastecode.io avatar
unknown
ruby
7 months ago
419 B
1
Indexable
Never
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
Leave a Comment