:current_user def connect self.current_user = find_verified_user end protected def find_verified_user if current_user = User.find_by(id: cookies.signed[:user_id]) current_user else reject_unauthorized_connection end end end end
end # app/channels/update_channel.rb class UpdateChannel < ApplicationCable::Channel end # app/channels/chat_channel.rb class ChatChannel < ApplicationCable::Channel end
stream_from "chat_#{params[:room]}" end end # app/channels/comments_channel.rb class CommentsChannel < ApplicationCable::Channel def subscribed post = Post.find(params[:id]) stream_for post end end
Room" }, { //Entry point when some data will be received received: function (data) { return this.appendLine(data); }, appendLine: function (data) { var html; html = this.createLine(data); return $("[data-chat-room='Best Room']").append(html); }, createLine: function (data) { return "data[ "sent_by" ] + “: "+ data[ "body" ]; } });