Sha256: fef87a9dd88fd6c71663edf5623123c5cbcf1a1a40dde60f5dd978b9dab46774

Contents?: true

Size: 1.19 KB

Versions: 46

Compression:

Stored size: 1.19 KB

Contents

module ActiveAdmin
  class Resource
    module Routes

      # Returns the routes prefix for this config
      def route_prefix
        namespace.module_name.try(:underscore)
      end

      def route_uncountable?
        controller.resources_configuration[:self][:route_collection_name] ==
              controller.resources_configuration[:self][:route_instance_name]
      end

      # Returns a symbol for the route to use to get to the
      # collection of this resource
      def route_collection_path(params = {})
        route, required_params = [], []

        route << route_prefix

        if belongs_to? && !belongs_to_config.optional?
          name = belongs_to_config.target.resource_name.singular
          route << name
          required_params << :"#{name}_id"
        end

        route << controller.resources_configuration[:self][:route_collection_name]

        route << (route_uncountable? ? 'index_path' : 'path')

        route_name = route.compact.join("_").to_sym

        route_params = params.values_at(*required_params)
        routes.send(route_name, *route_params)
      end

      private

      def routes
        Rails.application.routes.url_helpers
      end

    end
  end
end

Version data entries

46 entries across 46 versions & 2 rubygems

Version Path
lalala-4.0.0.dev.141 vendor/deps/active_admin/lib/active_admin/resource/routes.rb
lalala-4.0.0.dev.136 vendor/deps/active_admin/lib/active_admin/resource/routes.rb
lalala-4.0.0.dev.135 vendor/deps/active_admin/lib/active_admin/resource/routes.rb
lalala-4.0.0.dev.134 vendor/deps/active_admin/lib/active_admin/resource/routes.rb
lalala-4.0.0.dev.133 vendor/deps/active_admin/lib/active_admin/resource/routes.rb
lalala-4.0.0.dev.132 vendor/deps/active_admin/lib/active_admin/resource/routes.rb
lalala-4.0.0.dev.131 vendor/deps/active_admin/lib/active_admin/resource/routes.rb
lalala-4.0.0.dev.129 vendor/deps/active_admin/lib/active_admin/resource/routes.rb
lalala-4.0.0.dev.128 vendor/deps/active_admin/lib/active_admin/resource/routes.rb
lalala-4.0.0.dev.126 vendor/deps/active_admin/lib/active_admin/resource/routes.rb
lalala-4.0.0.dev.125 vendor/deps/active_admin/lib/active_admin/resource/routes.rb
lalala-4.0.0.dev.124 vendor/deps/active_admin/lib/active_admin/resource/routes.rb
lalala-4.0.0.dev.123 vendor/deps/active_admin/lib/active_admin/resource/routes.rb
lalala-4.0.0.dev.118 vendor/deps/active_admin/lib/active_admin/resource/routes.rb
lalala-4.0.0.dev.116 vendor/deps/active_admin/lib/active_admin/resource/routes.rb
lalala-4.0.0.dev.114 vendor/deps/active_admin/lib/active_admin/resource/routes.rb
lalala-4.0.0.dev.113 vendor/deps/active_admin/lib/active_admin/resource/routes.rb
lalala-4.0.0.dev.111 vendor/deps/active_admin/lib/active_admin/resource/routes.rb
lalala-4.0.0.dev.109 vendor/deps/active_admin/lib/active_admin/resource/routes.rb
lalala-4.0.0.dev.107 vendor/deps/active_admin/lib/active_admin/resource/routes.rb