Class: ThinkFeelDoEngine::Coach::MessagesController

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

Overview

Manages coach message handling.

Constant Summary

Constants inherited from ApplicationController

ApplicationController::CSRF_COOKIE_NAME, ApplicationController::CSRF_HEADER_NAME, ApplicationController::INACTIVE_MESSAGE, ApplicationController::ROOT_URI

Instance Method Summary collapse

Methods inherited from ApplicationController

#access_denied_resource_path, #after_sign_in_path_for, #after_sign_out_path_for, #raise_not_found!, #render_not_found

Instance Method Details

#createObject



39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/think_feel_do_engine/coach/messages_controller.rb', line 39

def create
  authorize! :create, Message
  @message = current_user.build_sent_message(message_params)
  if @message.save
    redirect_to coach_group_messages_url(@group), notice: "Message saved"
  else
    errors = @message.errors.full_messages.join(", ")
    redirect_to :back, alert: "Unable to save message: #{errors}"
  end
end

#indexObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/think_feel_do_engine/coach/messages_controller.rb', line 10

def index
  authorize! :show, Message

  @participants = grouped_assigned_participants

  render(
    locals: {
      received_messages: received_messages,
      sent_messages: sent_messages
    }
  )
end

#newObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/think_feel_do_engine/coach/messages_controller.rb', line 23

def new
  @new_message = current_user.build_sent_message
  authorize! :new, @new_message

  @reply_recipient =
    current_user.participants
                .find(params[:recipient_id]) if params[:recipient_id]

  render(
    locals: {
      message: message_for_reply,
      participants: grouped_assigned_participants
    }
  )
end

#replyObject



50
51
52
# File 'app/controllers/think_feel_do_engine/coach/messages_controller.rb', line 50

def reply
  authorize! :create, Message
end