Module: ActiveAdmin::ViewHelpers::DisplayHelper
- Included in:
- ActiveAdmin::ViewHelpers
- Defined in:
- lib/active_admin/view_helpers/display_helper.rb
Instance Method Summary collapse
-
#association_methods_for(resource) ⇒ Object
To prevent conflicts, we exclude any methods that happen to be associations.
-
#display_name(resource) ⇒ Object
Attempts to call any known display name methods on the resource.
-
#display_name_method_for(resource) ⇒ Object
Looks up and caches the first available display name method.
-
#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.
Instance Method Details
#association_methods_for(resource) ⇒ Object
To prevent conflicts, we exclude any methods that happen to be associations.
21 22 23 24 |
# File 'lib/active_admin/view_helpers/display_helper.rb', line 21 def association_methods_for(resource) return [] unless resource.class.respond_to? :reflect_on_all_associations resource.class.reflect_on_all_associations.map(&:name) end |
#display_name(resource) ⇒ Object
Attempts to call any known display name methods on the resource. See the setting in ‘application.rb` for the list of methods and their priority.
7 8 9 |
# File 'lib/active_admin/view_helpers/display_helper.rb', line 7 def display_name(resource) resource.send display_name_method_for resource if resource end |
#display_name_method_for(resource) ⇒ Object
Looks up and caches the first available display name method.
12 13 14 15 16 17 18 |
# File 'lib/active_admin/view_helpers/display_helper.rb', line 12 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) methods.detect{ |method| resource.respond_to? method } end 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
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/active_admin/view_helpers/display_helper.rb', line 30 def pretty_format(object) case object when String object when Arbre::Element object when Date, Time localize(object, :format => :long) when ActiveRecord::Base auto_link(object) else display_name(object) end end |