Sha256: b81296f3eac329b8eeb7a211c7149908f14c9d265a1fc2266684b1d90b63434c

Contents?: true

Size: 1.3 KB

Versions: 4

Compression:

Stored size: 1.3 KB

Contents

module ThinkFeelDoEngine
  module Coach
    # Enables viewing of messages sent to coaches.
    class ReceivedMessagesController < ApplicationController
      before_action :authenticate_user!, :set_group

      rescue_from ActiveRecord::RecordNotFound, with: :record_not_found

      def show
        @received_message = current_user.received_messages.find(params[:id])
        authorize! :show, @received_message
        @received_message.try(:mark_read)
        render(
          template: "think_feel_do_engine/messages/show",
          locals: {
            message: @received_message,
            compose_path: new_coach_group_message_path(@group),
            reply_path: reply_path(@received_message)
          }
        )
      end

      private

      def reply_path(received_message)
        new_coach_group_message_path(
          @group,
          # This Message.class IS DeliveredMessage
          body: "#{received_message.body}",
          message_id: received_message.id,
          recipient_id: received_message.message.sender_id,
          subject: "Reply: #{received_message.subject}"
        )
      end

      def record_not_found
        redirect_to main_app.root_url, alert: "Unable to find message"
      end

      def set_group
        @group = Group.find(params[:group_id])
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
think_feel_do_engine-3.10.9 app/controllers/think_feel_do_engine/coach/received_messages_controller.rb
think_feel_do_engine-3.10.8 app/controllers/think_feel_do_engine/coach/received_messages_controller.rb
think_feel_do_engine-3.10.7 app/controllers/think_feel_do_engine/coach/received_messages_controller.rb
think_feel_do_engine-3.10.6 app/controllers/think_feel_do_engine/coach/received_messages_controller.rb