Class: SimpleChat::ChatRoomsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- SimpleChat::ChatRoomsController
- Defined in:
- app/controllers/simple_chat/chat_rooms_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /chat_rooms.
-
#destroy ⇒ Object
DELETE /chat_rooms/1.
-
#edit ⇒ Object
GET /chat_rooms/1/edit.
-
#index ⇒ Object
GET /chat_rooms.
-
#new ⇒ Object
GET /chat_rooms/new.
-
#show ⇒ Object
GET /chat_rooms/1.
-
#update ⇒ Object
PATCH/PUT /chat_rooms/1.
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
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 |
#destroy ⇒ Object
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 |
#edit ⇒ Object
GET /chat_rooms/1/edit
27 28 |
# File 'app/controllers/simple_chat/chat_rooms_controller.rb', line 27 def edit end |
#index ⇒ Object
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 |
#new ⇒ Object
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 |
#show ⇒ Object
GET /chat_rooms/1
16 17 18 19 |
# File 'app/controllers/simple_chat/chat_rooms_controller.rb', line 16 def show @messages = @chat_room..select(&:persisted?) @message = @chat_room..build end |
#update ⇒ Object
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 |