Sha256: 2b273c8e3302e3558edb00efcf5d8274a7bf0bf084e3145fe0f5615a85b51f76

Contents?: true

Size: 1.36 KB

Versions: 18

Compression:

Stored size: 1.36 KB

Contents

module AdminIt
  #
  module Controller
    def self.included(base)
      base.class_eval do
        include Pundit if AdminIt::Env.pundit?
        before_filter :authenticate_user!

        attr_reader :context
        helper_method :context, :resource
        helper AdminIt::Helpers
        helper AdminIt::Engine.routes.url_helpers

        if AdminIt::Env.pundit?
          collections = @resource.collections.map(&:context_name)
          after_action :verify_authorized, except: collections
          after_action :verify_policy_scoped, only: collections
        end
      end
    end

    def resource
      self.class.instance_variable_get(:@resource)
    end

    def redirect_to_default
      if context.child?
        redirect_to(context.parent.class.url(context.parent, section: context.section))
      else
        redirect_to(resource[resource.default_context].url)
      end
    end

    private

    def load_context(context_class)
      @context = context_class.new(self)
      yield if block_given?
      layout = ['admin_it', params[:layout]].compact.join('_')
      unless performed?
        if layout == 'admin_it' && !request.query_parameters.empty?
          redirect_to request.path
        else
          Request.get(request).process!
          render template: "admin_it/#{context.name}", layout: layout
        end
      end
      @context.save
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
admin_it-1.3.8 lib/admin_it/controller.rb
admin_it-1.3.7 lib/admin_it/controller.rb
admin_it-1.3.6 lib/admin_it/controller.rb
admin_it-1.3.5 lib/admin_it/controller.rb
admin_it-1.3.4 lib/admin_it/controller.rb
admin_it-1.3.3 lib/admin_it/controller.rb
admin_it-1.3.2 lib/admin_it/controller.rb
admin_it-1.3.1 lib/admin_it/controller.rb
admin_it-1.3.0 lib/admin_it/controller.rb
admin_it-1.2.8 lib/admin_it/controller.rb
admin_it-1.2.7 lib/admin_it/controller.rb
admin_it-1.2.6 lib/admin_it/controller.rb
admin_it-1.2.5 lib/admin_it/controller.rb
admin_it-1.2.4 lib/admin_it/controller.rb
admin_it-1.2.3 lib/admin_it/controller.rb
admin_it-1.2.2 lib/admin_it/controller.rb
admin_it-1.2.1 lib/admin_it/controller.rb
admin_it-1.2.0 lib/admin_it/controller.rb