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_resource_for(klass)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns the ActiveAdmin::Resource instance for a class. 
- 
  
    
      #auto_link(resource, content = display_name(resource))  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Automatically links objects to their resource controllers. 
- 
  
    
      #auto_url_for(resource)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Like ‘auto_link`, except that it only returns a URL instead of a full <a> tag. 
Instance Method Details
#active_admin_resource_for(klass) ⇒ Object
Returns the ActiveAdmin::Resource instance for a class
| 38 39 40 41 42 | # File 'lib/active_admin/view_helpers/auto_link_helper.rb', line 38 def active_admin_resource_for(klass) if respond_to? :active_admin_namespace active_admin_namespace.resource_for klass end end | 
#auto_link(resource, content = display_name(resource)) ⇒ 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")
| 15 16 17 18 19 20 21 | # File 'lib/active_admin/view_helpers/auto_link_helper.rb', line 15 def auto_link(resource, content = display_name(resource)) if url = auto_url_for(resource) link_to content, url else content end end | 
#auto_url_for(resource) ⇒ Object
Like ‘auto_link`, except that it only returns a URL instead of a full <a> tag
| 24 25 26 27 28 29 30 31 32 33 34 35 | # File 'lib/active_admin/view_helpers/auto_link_helper.rb', line 24 def auto_url_for(resource) config = active_admin_resource_for(resource.class) return unless config if config.controller.action_methods.include?("show") && (ActiveAdmin::Auth::READ, resource) url_for config.route_instance_path resource, elsif config.controller.action_methods.include?("edit") && (ActiveAdmin::Auth::EDIT, resource) url_for config.route_edit_instance_path resource, end end |