Sha256: 2222a1567ab019838f981d1180cea64f11769a0d87aa722b91560c4f25785575
Contents?: true
Size: 1.29 KB
Versions: 3
Compression:
Stored size: 1.29 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 begin result = @resource.aasm(permitted_params_for_trigger_event[:machine_name].to_sym).fire!(permitted_params_for_trigger_event[:event_name].to_sym) rescue ActiveRecord::RecordInvalid => e result = false end if result flash[:notice] = t( 'rao.resources_controller.aasm_concern.trigger_event.success', event: permitted_params_for_trigger_event[:event_name], state: @resource.aasm(permitted_params_for_trigger_event[:machine_name].to_sym).current_state ) else flash[:danger] = t( 'rao.resources_controller.aasm_concern.trigger_event.failure', event: permitted_params_for_trigger_event[:event_name], errors: @resource.errors.full_messages.to_sentence ) 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
3 entries across 3 versions & 1 rubygems