Sha256: ed54e6c4de83e4d8e68bdf1087562954f800e75b76333b1fb50f2b9554138508

Contents?: true

Size: 1.06 KB

Versions: 12

Compression:

Stored size: 1.06 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, registration.route_instance_path(resource))
          rescue
            # ignored
          end
        end
        content
      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

12 entries across 12 versions & 3 rubygems

Version Path
activeadmin-0.6.6 lib/active_admin/view_helpers/auto_link_helper.rb
activeadmin-0.6.5 lib/active_admin/view_helpers/auto_link_helper.rb
activeadmin-0.6.4 lib/active_admin/view_helpers/auto_link_helper.rb
yousty-activeadmin-1.0.4.pre lib/active_admin/view_helpers/auto_link_helper.rb
yousty-activeadmin-1.0.3.pre lib/active_admin/view_helpers/auto_link_helper.rb
yousty-activeadmin-1.0.2.pre lib/active_admin/view_helpers/auto_link_helper.rb
activeadmin-0.6.3 lib/active_admin/view_helpers/auto_link_helper.rb
yousty-activeadmin-1.0.1.pre lib/active_admin/view_helpers/auto_link_helper.rb
yousty-activeadmin-1.0.0.pre lib/active_admin/view_helpers/auto_link_helper.rb
activeadmin-0.6.2 lib/active_admin/view_helpers/auto_link_helper.rb
activeadmin-0.6.1 lib/active_admin/view_helpers/auto_link_helper.rb
aa-rails4-0.6.0 lib/active_admin/view_helpers/auto_link_helper.rb