module ActiveAdmin::AutoLinkHelper
def active_admin_resource_for(klass)
While `active_admin_namespace` is a helper method, this method seems
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
def auto_link(resource, content = display_name(resource), **html_options)
eg: auto_link(@post, "My Link")
You can pass in the content to display
The default content in the link is returned from ActiveAdmin::DisplayHelper#display_name
the object is returned.
the resource has not been registered, a string representation of
Automatically links objects to their resource controllers. If
def auto_link(resource, content = display_name(resource), **html_options) if url = auto_url_for(resource) link_to content, url, html_options else content end end
def auto_logout_link_path
def auto_logout_link_path render_or_call_method_or_proc_on(self, active_admin_namespace.logout_link_path) end
def auto_url_for(resource)
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, url_options elsif config.controller.action_methods.include?("edit") && authorized?(ActiveAdmin::Auth::EDIT, resource) url_for config.route_edit_instance_path resource, url_options end end
def destroy_action_authorized?(resource_or_class)
def destroy_action_authorized?(resource_or_class) controller.action_methods.include?("destroy") && authorized?(ActiveAdmin::Auth::DESTROY, resource_or_class) end
def edit_action_authorized?(resource_or_class)
def edit_action_authorized?(resource_or_class) controller.action_methods.include?("edit") && authorized?(ActiveAdmin::Auth::EDIT, resource_or_class) end
def new_action_authorized?(resource_or_class)
def new_action_authorized?(resource_or_class) controller.action_methods.include?("new") && authorized?(ActiveAdmin::Auth::NEW, resource_or_class) end
def show_action_authorized?(resource_or_class)
def show_action_authorized?(resource_or_class) controller.action_methods.include?("show") && authorized?(ActiveAdmin::Auth::READ, resource_or_class) end