Sha256: 6deeffaccc3383c764a47dca1800ecc27486204c1d16e1118663b7559906cd02

Contents?: true

Size: 1.13 KB

Versions: 9

Compression:

Stored size: 1.13 KB

Contents

require "active_admin/resource"
require "active_admin/resource/model"

module ActiveAdmin
  class ResourceController < BaseController
    module PolymorphicRoutes
      def polymorphic_url(record_or_hash_or_array, options = {})
        super(map_named_resources_for(record_or_hash_or_array), options)
      end

      def polymorphic_path(record_or_hash_or_array, options = {})
        super(map_named_resources_for(record_or_hash_or_array), options)
      end

      private

      def map_named_resources_for(record_or_hash_or_array)
        return record_or_hash_or_array unless record_or_hash_or_array.is_a?(Array)

        record_or_hash_or_array.map { |record| to_named_resource(record) }
      end

      def to_named_resource(record)
        if record.is_a?(resource_class)
          return ActiveAdmin::Model.new(active_admin_config, record)
        end

        belongs_to_resource = active_admin_config.belongs_to_config.try(:resource)
        if belongs_to_resource && record.is_a?(belongs_to_resource.resource_class)
          return ActiveAdmin::Model.new(belongs_to_resource, record)
        end

        record
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/activeadmin-2.9.0/lib/active_admin/resource_controller/polymorphic_routes.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/activeadmin-2.9.0/lib/active_admin/resource_controller/polymorphic_routes.rb
activeadmin-2.9.0 lib/active_admin/resource_controller/polymorphic_routes.rb
activeadmin-2.8.1 lib/active_admin/resource_controller/polymorphic_routes.rb
activeadmin-2.8.0 lib/active_admin/resource_controller/polymorphic_routes.rb
activeadmin-2.7.0 lib/active_admin/resource_controller/polymorphic_routes.rb
activeadmin-2.6.1 lib/active_admin/resource_controller/polymorphic_routes.rb
activeadmin-2.6.0 lib/active_admin/resource_controller/polymorphic_routes.rb
activeadmin-2.5.0 lib/active_admin/resource_controller/polymorphic_routes.rb