Method: ActiveAdmin::ViewHelpers::DisplayHelper#display_name_method_for

Defined in:
lib/active_admin/view_helpers/display_helper.rb

#display_name_method_for(resource) ⇒ Object

Looks up and caches the first available display name method. To prevent conflicts, we exclude any methods that happen to be associations. If no methods are available and we’re about to use the Kernel’s to_s, provide our own.



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/active_admin/view_helpers/display_helper.rb', line 24

def display_name_method_for(resource)
  @@display_name_methods_cache ||= {}
  @@display_name_methods_cache[resource.class] ||= begin
    methods = active_admin_application.display_name_methods - association_methods_for(resource)
    method  = methods.detect{ |method| resource.respond_to? method }

    if method != :to_s || resource.method(method).source_location
      method
    else
      DISPLAY_NAME_FALLBACK
    end
  end
end