Sha256: a817af2e7957dd6182f6404a12c67c0d3dc9f244df56b9e377e116d9ccca577d

Contents?: true

Size: 1.18 KB

Versions: 5

Compression:

Stored size: 1.18 KB

Contents

module ActiveAdmin
  module ViewHelpers
    module AutoLinkHelper

      # Automatically links objects to their resource controllers. If
      # the resource has not been registered, a string representation of
      # the object is returned.
      #
      # The default content in the link is returned from ActiveAdmin::ViewHelpers::DisplayHelper#display_name
      #
      # You can pass in the content to display
      #   eg: auto_link(@post, "My Link Content")
      #
      def auto_link(resource, link_content = nil)
        content = link_content || display_name(resource)
        if url = auto_url_for(resource)
          content = link_to(content, url)
        end
        content
      end

      # Like `auto_link`, except that it only returns a URL instead of a full <a> tag
      def auto_url_for(resource)
        if config = active_admin_resource_for(resource.class)
          url_for config.route_instance_path resource
        end
      end

      # Returns the ActiveAdmin::Resource instance for a class
      def active_admin_resource_for(klass)
        return nil unless respond_to?(:active_admin_namespace)
        active_admin_namespace.resource_for(klass)
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
active_administration-0.0.3 lib/active_admin/view_helpers/auto_link_helper.rb
activeadministration-0.0.2 lib/active_admin/view_helpers/auto_link_helper.rb
active_administration-0.0.2 lib/active_admin/view_helpers/auto_link_helper.rb
activeadministration-0.0.1 lib/active_admin/view_helpers/auto_link_helper.rb
active_administration-0.0.1 lib/active_admin/view_helpers/auto_link_helper.rb