Class: TurboChat::ChatMessagesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/turbo_chat/chat_messages_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



13
14
15
16
17
18
# File 'app/controllers/turbo_chat/chat_messages_controller.rb', line 13

def create
  return respond_to_clear_signal_request if clear_signal_request?

  build_chat_message
  @chat_message.save ? respond_to_chat_message_create_success : respond_to_chat_message_create_failure
end

#indexObject



9
10
11
# File 'app/controllers/turbo_chat/chat_messages_controller.rb', line 9

def index
  @chat_messages = @chat.visible_messages
end

#updateObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/turbo_chat/chat_messages_controller.rb', line 20

def update
  updated = @chat_message.update(edit_chat_message_params)
  if turbo_stream_request?
    return render_chat_message_update(force_edit_open: !updated, status: updated ? :ok : :unprocessable_entity)
  end

  if updated
    redirect_to chat_path(@chat), notice: "Message updated"
  else
    redirect_to chat_path(@chat), alert: @chat_message.errors.full_messages.to_sentence
  end
end