Sha256: 91fc6b7e506b700a5b33bfdbb146d50aef3d3e2d64b656626d3bc10061445958

Contents?: true

Size: 980 Bytes

Versions: 49

Compression:

Stored size: 980 Bytes

Contents

require_dependency "para/application_controller"

module Para
  module Admin
    class FormResourcesController < Para::Admin::ResourcesController
      before_action :load_and_authorize_form
      after_action :attach_resource_to_component, only: [:create]

      # Include after resource loading to allow the concern to use the resource
      # in before_action hooks
      include Para::Admin::ResourceControllerConcerns

      private

      def attach_resource_to_component
        return unless resource.persisted?
        @component.resource = resource
        @component.save
      end

      def load_and_authorize_form
        loader = self.class.cancan_resource_class.new(
          self, :resource, parent: false, class: resource_model.name,
          singleton: true, through: :component, bypass_params_assignation: true
        )

        loader.load_and_authorize_resource
        instance_variable_set(:"@#{ resource_name }", @resource)
      end
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
para-0.7.3.p5 app/controllers/para/admin/form_resources_controller.rb
para-0.7.3.p4 app/controllers/para/admin/form_resources_controller.rb
para-0.7.3.p3 app/controllers/para/admin/form_resources_controller.rb
para-0.7.3.p2 app/controllers/para/admin/form_resources_controller.rb
para-0.7.3.p1 app/controllers/para/admin/form_resources_controller.rb
para-0.7.3 app/controllers/para/admin/form_resources_controller.rb
para-0.7.2 app/controllers/para/admin/form_resources_controller.rb
para-0.7.1 app/controllers/para/admin/form_resources_controller.rb
para-0.7.0 app/controllers/para/admin/form_resources_controller.rb