Sha256: 2e1f34ecd11864d7b9e955ff517647bdf3c4aac4616c9bd87e2fd513302c5162

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 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 registration = active_admin_resource_for(resource.class)
          begin
            content = link_to(content, send(registration.route_instance_path, resource))
          rescue
          end
        end
        content
      end

      # Returns the ActiveAdmin::Resource instance for a class
      def active_admin_resource_for(klass)
        active_admin_namespace.resource_for(klass)
      end

      # Returns the current Active Admin namespace
      def active_admin_namespace
        if respond_to?(:active_admin_config) && active_admin_config
          active_admin_config.namespace
        else
          ActiveAdmin::Namespace.new(ActiveAdmin.default_namespace)
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
activeadmin-0.2.2 lib/active_admin/view_helpers/auto_link_helper.rb
activeadmin-0.2.1 lib/active_admin/view_helpers/auto_link_helper.rb
activeadmin-0.2.0 lib/active_admin/view_helpers/auto_link_helper.rb