Sha256: a21a88345a9dbebf3ebca840a9ee0b1f67668469f53cd5fb2d1112b386041bba

Contents?: true

Size: 1.44 KB

Versions: 30

Compression:

Stored size: 1.44 KB

Contents

require_dependency "think_feel_do_engine/application_controller"

module ThinkFeelDoEngine
  module Coach
    # Manage messages from the site to Participants.
    class SiteMessagesController < ApplicationController
      before_action :authenticate_user!, :set_group
      load_and_authorize_resource except: [:index]

      def index
        authorize! :index, SiteMessage
        participant_ids = current_user.participants_for_group(@group).ids
        @site_messages =
          SiteMessage
          .where(participant_id: participant_ids)
      end

      def show
      end

      def new
        @participants = current_user.participants_for_group(@group)
        redirect_to(coach_group_site_messages_path(@group),
                    alert: "A group must have participants in order "\
                            " to send site message.") if @participants.empty?
      end

      def create
        if @site_message.save
          SiteMessageMailer.general(@site_message).deliver

          redirect_to coach_group_site_message_path(@group, @site_message),
                      notice: "Site message was successfully created."
        else
          render :new
        end
      end

      private

      def site_message_params
        params
          .require(:site_message)
          .permit(
            :participant_id, :subject, :body
          )
      end

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

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
think_feel_do_engine-3.18.0 app/controllers/think_feel_do_engine/coach/site_messages_controller.rb
think_feel_do_engine-3.17.2 app/controllers/think_feel_do_engine/coach/site_messages_controller.rb
think_feel_do_engine-3.17.1 app/controllers/think_feel_do_engine/coach/site_messages_controller.rb
think_feel_do_engine-3.17.0 app/controllers/think_feel_do_engine/coach/site_messages_controller.rb
think_feel_do_engine-3.16.3 app/controllers/think_feel_do_engine/coach/site_messages_controller.rb
think_feel_do_engine-3.16.2 app/controllers/think_feel_do_engine/coach/site_messages_controller.rb
think_feel_do_engine-3.16.1 app/controllers/think_feel_do_engine/coach/site_messages_controller.rb
think_feel_do_engine-3.15.7 app/controllers/think_feel_do_engine/coach/site_messages_controller.rb
think_feel_do_engine-3.16.0 app/controllers/think_feel_do_engine/coach/site_messages_controller.rb
think_feel_do_engine-3.15.6 app/controllers/think_feel_do_engine/coach/site_messages_controller.rb
think_feel_do_engine-3.15.5 app/controllers/think_feel_do_engine/coach/site_messages_controller.rb
think_feel_do_engine-3.15.4 app/controllers/think_feel_do_engine/coach/site_messages_controller.rb
think_feel_do_engine-3.15.3 app/controllers/think_feel_do_engine/coach/site_messages_controller.rb
think_feel_do_engine-3.15.2 app/controllers/think_feel_do_engine/coach/site_messages_controller.rb
think_feel_do_engine-3.15.1 app/controllers/think_feel_do_engine/coach/site_messages_controller.rb
think_feel_do_engine-3.15.0 app/controllers/think_feel_do_engine/coach/site_messages_controller.rb
think_feel_do_engine-3.14.9 app/controllers/think_feel_do_engine/coach/site_messages_controller.rb
think_feel_do_engine-3.14.8 app/controllers/think_feel_do_engine/coach/site_messages_controller.rb
think_feel_do_engine-3.14.7 app/controllers/think_feel_do_engine/coach/site_messages_controller.rb
think_feel_do_engine-3.14.6 app/controllers/think_feel_do_engine/coach/site_messages_controller.rb