Module: ActiveAdmin::AutoLinkHelper

Defined in:
app/helpers/active_admin/auto_link_helper.rb

Instance Method Summary collapse

Instance Method Details

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::DisplayHelper#display_name

You can pass in the content to display

eg: auto_link(@post, "My Link")


13
14
15
16
17
18
19
# File 'app/helpers/active_admin/auto_link_helper.rb', line 13

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


51
52
53
# File 'app/helpers/active_admin/auto_link_helper.rb', line 51

def auto_logout_link_path
  render_or_call_method_or_proc_on(self, active_admin_namespace.logout_link_path)
end

#auto_url_for(resource) ⇒ Object

Like ‘auto_link`, except that it only returns a URL for the resource



22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/helpers/active_admin/auto_link_helper.rb', line 22

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

#destroy_action_authorized?(resource_or_class) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'app/helpers/active_admin/auto_link_helper.rb', line 47

def destroy_action_authorized?(resource_or_class)
  controller.action_methods.include?("destroy") && authorized?(ActiveAdmin::Auth::DESTROY, resource_or_class)
end

#edit_action_authorized?(resource_or_class) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/helpers/active_admin/auto_link_helper.rb', line 43

def edit_action_authorized?(resource_or_class)
  controller.action_methods.include?("edit") && authorized?(ActiveAdmin::Auth::EDIT, resource_or_class)
end

#new_action_authorized?(resource_or_class) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/helpers/active_admin/auto_link_helper.rb', line 35

def new_action_authorized?(resource_or_class)
  controller.action_methods.include?("new") && authorized?(ActiveAdmin::Auth::NEW, resource_or_class)
end

#show_action_authorized?(resource_or_class) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/helpers/active_admin/auto_link_helper.rb', line 39

def show_action_authorized?(resource_or_class)
  controller.action_methods.include?("show") && authorized?(ActiveAdmin::Auth::READ, resource_or_class)
end