Sha256: fa8d1929e1968e4e2447a83f745dd6120d0eb77e073a06d91f1ef5204f537f01

Contents?: true

Size: 1.46 KB

Versions: 25

Compression:

Stored size: 1.46 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")
      #
      def auto_link(resource, content = display_name(resource))
        if url = auto_url_for(resource)
          link_to content, url
        else
          content
        end
      end

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

        if config.controller.action_methods.include?("show") &&
          authorized?(ActiveAdmin::Auth::READ, resource)
          url_for config.route_instance_path resource
        elsif config.controller.action_methods.include?("edit") &&
          authorized?(ActiveAdmin::Auth::UPDATE, resource)
          url_for config.route_edit_instance_path resource
        end
      end

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

    end
  end
end

Version data entries

25 entries across 25 versions & 4 rubygems

Version Path
activeadmin_addons-1.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/view_helpers/auto_link_helper.rb
activeadmin_addons-1.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/view_helpers/auto_link_helper.rb
yousty-activeadmin-1.0.17.pre lib/active_admin/view_helpers/auto_link_helper.rb
yousty-activeadmin-1.0.16.pre lib/active_admin/view_helpers/auto_link_helper.rb
activeadmin_addons-1.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/view_helpers/auto_link_helper.rb
activeadmin_addons-1.0.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/view_helpers/auto_link_helper.rb
activeadmin_addons-1.0.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/view_helpers/auto_link_helper.rb
yousty-activeadmin-1.0.15.pre lib/active_admin/view_helpers/auto_link_helper.rb
activeadmin-orac-1.0.0.pre4 lib/active_admin/view_helpers/auto_link_helper.rb
activeadmin-orac-1.0.0 lib/active_admin/view_helpers/auto_link_helper.rb
activeadmin-orac-1.0.0.pre.orac lib/active_admin/view_helpers/auto_link_helper.rb
yousty-activeadmin-1.0.14.pre lib/active_admin/view_helpers/auto_link_helper.rb
yousty-activeadmin-1.0.13.pre lib/active_admin/view_helpers/auto_link_helper.rb
yousty-activeadmin-1.0.12.pre lib/active_admin/view_helpers/auto_link_helper.rb
yousty-activeadmin-1.0.11.pre lib/active_admin/view_helpers/auto_link_helper.rb
yousty-activeadmin-1.0.10.pre lib/active_admin/view_helpers/auto_link_helper.rb
yousty-activeadmin-1.0.9.pre lib/active_admin/view_helpers/auto_link_helper.rb
yousty-activeadmin-1.0.8.pre lib/active_admin/view_helpers/auto_link_helper.rb
activeadmin-1.0.0.pre4 lib/active_admin/view_helpers/auto_link_helper.rb
activeadmin-1.0.0.pre3 lib/active_admin/view_helpers/auto_link_helper.rb