Sha256: 8867773fb93873ecc6a2580e2d32a09f52fa5c431a602e6aac76e297effec1e6

Contents?: true

Size: 1.37 KB

Versions: 22

Compression:

Stored size: 1.37 KB

Contents

module MessageTrain
  class ParticipantsController < MessageTrain::ApplicationController
    before_filter :load_participants
    before_filter :load_participant, only: :show

    # GET /box/:division/participants/:model
    def index
      respond_to do |format|
        format.json { render :index }
      end
    end

    # GET /box/:division/participants/:model/:id
    def show
      respond_to do |format|
        format.json { render :show }
      end
    end

    private

      def load_participants
        if params[:model].empty?
          raise ActiveRecord::RecordNotFound
        end
        model_sym = params[:model].to_sym
        model = MessageTrain.configuration.recipient_tables[model_sym].constantize
        method = MessageTrain.configuration.address_book_methods[model_sym]
        fallback_method = MessageTrain.configuration.address_book_method
        current_participant = send(MessageTrain.configuration.current_user_method)
        if !method.nil? && model.respond_to?(method)
          @participants = model.send(method, current_participant)
        elsif !fallback_method.nil? && model.respond_to?(fallback_method)
          @participants = model.send(fallback_method, current_participant)
        else
          @participants = model.all
        end
      end

      def load_participant
        @participant = @participants.find(params[:id])
      end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
message_train-0.4.6 app/controllers/message_train/participants_controller.rb
message_train-0.4.5 app/controllers/message_train/participants_controller.rb
message_train-0.4.4 app/controllers/message_train/participants_controller.rb
message_train-0.4.3 app/controllers/message_train/participants_controller.rb
message_train-0.4.2 app/controllers/message_train/participants_controller.rb
message_train-0.4.1 app/controllers/message_train/participants_controller.rb
message_train-0.4.0 app/controllers/message_train/participants_controller.rb
message_train-0.3.1 app/controllers/message_train/participants_controller.rb
message_train-0.3.0 app/controllers/message_train/participants_controller.rb
message_train-0.2.12 app/controllers/message_train/participants_controller.rb
message_train-0.2.11 app/controllers/message_train/participants_controller.rb
message_train-0.2.10 app/controllers/message_train/participants_controller.rb
message_train-0.2.9 app/controllers/message_train/participants_controller.rb
message_train-0.2.8 app/controllers/message_train/participants_controller.rb
message_train-0.2.7 app/controllers/message_train/participants_controller.rb
message_train-0.2.6 app/controllers/message_train/participants_controller.rb
message_train-0.2.5 app/controllers/message_train/participants_controller.rb
message_train-0.2.4 app/controllers/message_train/participants_controller.rb
message_train-0.2.3 app/controllers/message_train/participants_controller.rb
message_train-0.2.2 app/controllers/message_train/participants_controller.rb