Class: SimpleChat::ChatMembersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/simple_chat/chat_members_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#simple_chat_current_user

Instance Method Details

#createObject



5
6
7
8
9
10
11
12
13
# File 'app/controllers/simple_chat/chat_members_controller.rb', line 5

def create
  @chat_member = @chat_room.chat_members.find_or_initialize_by(user: simple_chat_current_user)

  if @chat_member.save
    redirect_to @chat_room, notice: "You are now a member of this chat room."
  else
    redirect_to @chat_room, alert: "Unable to join chat room."
  end
end

#destroyObject



15
16
17
18
19
# File 'app/controllers/simple_chat/chat_members_controller.rb', line 15

def destroy
  @chat_member = @chat_room.chat_members.find_by(user: simple_chat_current_user)
  @chat_member&.destroy
  redirect_to chat_rooms_path, notice: "You have left the chat room."
end