Sha256: fcde0b03b963a1e7045b812ea4f1bb754fdbaae42c2960246079402bdd5a4481

Contents?: true

Size: 947 Bytes

Versions: 18

Compression:

Stored size: 947 Bytes

Contents

require_dependency 'avo/application_controller'

module Avo
  class ActionsController < ApplicationController
    def index
      avo_actions = avo_resource.get_actions
      actions = []

      if params[:resource_id].present?
        model = resource_model.find params[:resource_id]
      end

      avo_actions.each do |action|
        actions.push(action.new.render_response model, avo_resource)
      end

      render json: {
        actions: actions,
      }
    end

    def handle
      models = resource_model.find action_params[:resource_ids]
      avo_action = action_params[:action_class].safe_constantize.new
      avo_action.handle_action(request, models, action_params[:fields])

      render json: {
        success: true,
        response: avo_action.response,
      }
    end

    private
      def action_params
        params.permit(:resource_name, :action_id, :action_class, resource_ids: [], fields: {})
      end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
avo-0.4.10 app/controllers/avo/actions_controller.rb
avo-0.4.9 app/controllers/avo/actions_controller.rb
avo-0.4.8 app/controllers/avo/actions_controller.rb
avo-0.4.7 app/controllers/avo/actions_controller.rb
avo-0.4.6 app/controllers/avo/actions_controller.rb
avo-0.4.5 app/controllers/avo/actions_controller.rb
avo-0.4.4 app/controllers/avo/actions_controller.rb
avo-0.4.3 app/controllers/avo/actions_controller.rb
avo-0.4.2 app/controllers/avo/actions_controller.rb
avo-0.4.1 app/controllers/avo/actions_controller.rb
avo-0.3.2 app/controllers/avo/actions_controller.rb
avo-0.3.1 app/controllers/avo/actions_controller.rb
avo-0.2.5 app/controllers/avo/actions_controller.rb
avo-0.2.4 app/controllers/avo/actions_controller.rb
avo-0.2.3 app/controllers/avo/actions_controller.rb
avo-0.2.2 app/controllers/avo/actions_controller.rb
avo-0.2.1 app/controllers/avo/actions_controller.rb
avo-0.2.0 app/controllers/avo/actions_controller.rb