Module: ActiveAdmin::ViewHelpers::AutoLinkHelper
- Included in:
- ActiveAdmin::ViewHelpers
- Defined in:
- lib/active_admin/view_helpers/auto_link_helper.rb
Instance Method Summary collapse
-
#active_admin_namespace ⇒ Object
Returns the current Active Admin namespace.
-
#active_admin_resource_for(klass) ⇒ Object
Returns the ActiveAdmin::Resource instance for a class.
-
#auto_link(resource, link_content = nil) ⇒ Object
Automatically links objects to their resource controllers.
Instance Method Details
#active_admin_namespace ⇒ Object
Returns the current Active Admin namespace
31 32 33 34 35 36 37 38 |
# File 'lib/active_admin/view_helpers/auto_link_helper.rb', line 31 def active_admin_namespace if respond_to?(:active_admin_config) && active_admin_config active_admin_config.namespace else # Return a default namespace if none exists active_admin_application.find_or_create_namespace(active_admin_application.default_namespace) end end |
#active_admin_resource_for(klass) ⇒ Object
Returns the ActiveAdmin::Resource instance for a class
26 27 28 |
# File 'lib/active_admin/view_helpers/auto_link_helper.rb', line 26 def active_admin_resource_for(klass) active_admin_namespace.resource_for(klass) end |
#auto_link(resource, link_content = nil) ⇒ Object
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")
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/active_admin/view_helpers/auto_link_helper.rb', line 14 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 |