Module: ActiveAdmin::AutoLinkHelper
- Defined in:
- app/helpers/active_admin/auto_link_helper.rb
Instance Method Summary collapse
-
#auto_link(resource, content = display_name(resource), **html_options) ⇒ Object
Automatically links objects to their resource controllers.
- #auto_logout_link_path ⇒ Object
-
#auto_url_for(resource) ⇒ Object
Like ‘auto_link`, except that it only returns a URL for the resource.
- #destroy_action_authorized?(resource_or_class) ⇒ Boolean
- #edit_action_authorized?(resource_or_class) ⇒ Boolean
- #new_action_authorized?(resource_or_class) ⇒ Boolean
- #show_action_authorized?(resource_or_class) ⇒ Boolean
Instance Method Details
#auto_link(resource, content = display_name(resource), **html_options) ⇒ 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::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), **) if url = auto_url_for(resource) link_to content, url, else content end end |
#auto_logout_link_path ⇒ Object
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") && (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 |
#destroy_action_authorized?(resource_or_class) ⇒ Boolean
47 48 49 |
# File 'app/helpers/active_admin/auto_link_helper.rb', line 47 def (resource_or_class) controller.action_methods.include?("destroy") && (ActiveAdmin::Auth::DESTROY, resource_or_class) end |
#edit_action_authorized?(resource_or_class) ⇒ Boolean
43 44 45 |
# File 'app/helpers/active_admin/auto_link_helper.rb', line 43 def (resource_or_class) controller.action_methods.include?("edit") && (ActiveAdmin::Auth::EDIT, resource_or_class) end |
#new_action_authorized?(resource_or_class) ⇒ Boolean
35 36 37 |
# File 'app/helpers/active_admin/auto_link_helper.rb', line 35 def (resource_or_class) controller.action_methods.include?("new") && (ActiveAdmin::Auth::NEW, resource_or_class) end |
#show_action_authorized?(resource_or_class) ⇒ Boolean
39 40 41 |
# File 'app/helpers/active_admin/auto_link_helper.rb', line 39 def (resource_or_class) controller.action_methods.include?("show") && (ActiveAdmin::Auth::READ, resource_or_class) end |