Class: Messaged::RoomsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/messaged/rooms_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/messaged/rooms_controller.rb', line 23

def create
  @room = Room.new(room_params)
  if @room.save
    respond_to do |format|
      format.html { redirect_to @room }
    end
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



44
45
46
47
48
49
50
# File 'app/controllers/messaged/rooms_controller.rb', line 44

def destroy
  @room.destroy
  respond_to do |format|
    format.turbo_stream { render turbo_stream: turbo_stream.remove(@room) }
    format.html         { redirect_to rooms_url }
  end
end

#editObject



34
# File 'app/controllers/messaged/rooms_controller.rb', line 34

def edit; end

#indexObject



6
7
8
# File 'app/controllers/messaged/rooms_controller.rb', line 6

def index
  @rooms = Room.all
end

#newObject



16
17
18
19
20
21
# File 'app/controllers/messaged/rooms_controller.rb', line 16

def new
  @room = Room.new
  @recipient = Messaged.user_class.find(params[:recipient]) if params.dig(:recipient)
  return unless messaged_current_owner && messaged_current_owner.class != Messaged::NullUser
  @room = messaged_current_owner.rooms.build
end

#showObject



10
11
12
13
14
# File 'app/controllers/messaged/rooms_controller.rb', line 10

def show
  @new_message = Message.new
  return unless messaged_current_owner && messaged_current_owner.class != Messaged::NullUser
  @new_message = messaged_current_owner.messages.build
end

#updateObject



36
37
38
39
40
41
42
# File 'app/controllers/messaged/rooms_controller.rb', line 36

def update
  if @room.update(room_params)
    render @room
  else
    render :edit, status: :unprocessable_entity
  end
end