Class: Messaged::MessagesController

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

Instance Method Summary collapse

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/messaged/messages_controller.rb', line 21

def create
  @message = Message.new(message_params)
  if @message.save
    if messaged_current_owner && messaged_current_owner.class != Messaged::NullUser
      @new_message = messaged_current_owner.messages.build
    else
      @new_message = Message.new
    end
    respond_to do |format|
      format.turbo_stream do
        render turbo_stream: turbo_stream.append(:messages, partial: "messaged/messages/message",
          locals: { message: @message })
      end
      format.html { redirect_to messages_url }
    end
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



51
52
53
54
55
56
57
# File 'app/controllers/messaged/messages_controller.rb', line 51

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

#editObject



41
# File 'app/controllers/messaged/messages_controller.rb', line 41

def edit; end

#indexObject



6
7
8
9
10
11
# File 'app/controllers/messaged/messages_controller.rb', line 6

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

#newObject



15
16
17
18
19
# File 'app/controllers/messaged/messages_controller.rb', line 15

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

#showObject



13
# File 'app/controllers/messaged/messages_controller.rb', line 13

def show; end

#updateObject



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

def update
if @message.update(message_params)
  render @message
else
  render :edit, status: :unprocessable_entity
end
end