Module: ActiveAdmin::ViewHelpers::DisplayHelper

Included in:
ActiveAdmin::ViewHelpers
Defined in:
lib/active_admin/view_helpers/display_helper.rb

Instance Method Summary collapse

Instance Method Details

#display_name(resource) ⇒ Object

Tries to display an object with as friendly of output as possible.



13
14
15
# File 'lib/active_admin/view_helpers/display_helper.rb', line 13

def display_name(resource)
  resource.send(display_name_method_for(resource))
end

#display_name_method_for(resource) ⇒ Object



5
6
7
8
9
# File 'lib/active_admin/view_helpers/display_helper.rb', line 5

def display_name_method_for(resource)
  @@display_name_methods_cache ||= {}
  @@display_name_methods_cache[resource.class] ||= 
    active_admin_application.display_name_methods.find{|method| resource.respond_to? method }
end

#pretty_format(object) ⇒ Object

Return a pretty string for any object Date Time are formatted via #localize with :format => :long ActiveRecord objects are formatted via #auto_link We attempt to #display_name of any other objects



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

def pretty_format(object)
  case object
  when String
    object
  when Arbre::HTML::Element
    object
  when Date, Time
    localize(object, :format => :long)
  when ActiveRecord::Base
    auto_link(object)
  else
    display_name(object)
  end
end