Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
25 lines (19 sloc) 677 Bytes
class MessagesController < ApplicationController
before_action :authenticate_user!
before_action :set_conversation
def create
@message = @conversation.messages.create message_params
ActionCable.server.broadcast "message_channel_#{@conversation.id}",
message: render_message(@message)
end
private
def message_params
params.require(:message).permit(:body).merge(user_id: current_user.id)
end
def set_conversation
@conversation = Conversation.mine(current_user).find(params[:conversation_id])
end
def render_message(message)
render(partial: 'messages/message', locals: { message: message })
end
end