Sha256: 72e20fc830ed3df44aa8e6ad6a27f9571bc4f2503ed6b572f64ba9297492ef2c

Contents?: true

Size: 1.11 KB

Versions: 6

Compression:

Stored size: 1.11 KB

Contents

module Rao
  module ResourcesController
    module AasmConcern
      extend ActiveSupport::Concern

      included do
        before_action :load_resource_for_trigger_event, only: [:trigger_event]
      end

      def trigger_event
        if @resource.aasm(permitted_params_for_trigger_event[:machine_name].to_sym).fire!(permitted_params_for_trigger_event[:event_name].to_sym)
          flash[:notice] = t('rao.resources_controller.aasm_concern.trigger_event.success', state: @resource.aasm(permitted_params_for_trigger_event[:machine_name].to_sym).current_state, event: permitted_params_for_trigger_event[:event_name])
        else
          flash[:notice] = t('rao.resources_controller.aasm_concern.trigger_event.failure', state: @resource.aasm(permitted_params_for_trigger_event[:machine_name].to_sym).current_state, event: permitted_params_for_trigger_event[:event_name])
        end
        redirect_back(fallback_location: root_path)
      end

      private

      def permitted_params_for_trigger_event
        params.permit!
      end

      def load_resource_for_trigger_event
        load_resource
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rao-resources_controller-0.0.49.pre app/concerns/rao/resources_controller/aasm_concern.rb
rao-resources_controller-0.0.48.pre app/concerns/rao/resources_controller/aasm_concern.rb
rao-resources_controller-0.0.47.pre app/concerns/rao/resources_controller/aasm_concern.rb
rao-resources_controller-0.0.46.pre app/concerns/rao/resources_controller/aasm_concern.rb
rao-resources_controller-0.0.45.pre app/concerns/rao/resources_controller/aasm_concern.rb
rao-resources_controller-0.0.44.pre app/concerns/rao/resources_controller/aasm_concern.rb