Class: SimpleChat::ChatRoomsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#simple_chat_current_user

Instance Method Details

#createObject

POST /chat_rooms



31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/simple_chat/chat_rooms_controller.rb', line 31

def create
  @chat_room = ChatRoom.new(chat_room_params)

  if @chat_room.save
    @chat_room.chat_members.create(user: simple_chat_current_user) if simple_chat_current_user
    redirect_to @chat_room, notice: "Chat room was successfully created and you have been added as a member."
  else
    render :new, status: :unprocessable_content
  end
end

#destroyObject

DELETE /chat_rooms/1



52
53
54
55
# File 'app/controllers/simple_chat/chat_rooms_controller.rb', line 52

def destroy
  @chat_room.destroy!
  redirect_to chat_rooms_path, notice: "Chat room was successfully destroyed.", status: :see_other
end

#editObject

GET /chat_rooms/1/edit



27
28
# File 'app/controllers/simple_chat/chat_rooms_controller.rb', line 27

def edit
end

#indexObject

GET /chat_rooms



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

def index
  if simple_chat_current_user
    @chat_rooms = ChatRoom.for_user(simple_chat_current_user)
  else
    @chat_rooms = ChatRoom.none
  end
end

#newObject

GET /chat_rooms/new



22
23
24
# File 'app/controllers/simple_chat/chat_rooms_controller.rb', line 22

def new
  @chat_room = ChatRoom.new
end

#showObject

GET /chat_rooms/1



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

def show
  @messages = @chat_room.messages.select(&:persisted?)
  @message = @chat_room.messages.build
end

#updateObject

PATCH/PUT /chat_rooms/1



43
44
45
46
47
48
49
# File 'app/controllers/simple_chat/chat_rooms_controller.rb', line 43

def update
  if @chat_room.update(chat_room_params)
    redirect_to @chat_room, notice: "Chat room was successfully updated.", status: :see_other
  else
    render :edit, status: :unprocessable_content
  end
end