Module: ActiveAdmin::DisplayHelper
- Defined in:
- app/helpers/active_admin/display_helper.rb
Constant Summary collapse
- DISPLAY_NAME_FALLBACK =
-> { klass = self.class name = if klass.respond_to?(:model_name) if klass.respond_to?(:primary_key) "#{klass.model_name.human} ##{send(klass.primary_key)}" else klass.model_name.human end elsif klass.respond_to?(:primary_key) " ##{send(klass.primary_key)}" end name.present? ? name : to_s }
Instance Method Summary collapse
-
#display_name(resource) ⇒ Object
Attempts to call any known display name methods on the resource.
- #format_attribute(resource, attr) ⇒ Object
-
#pretty_format(object) ⇒ Object
Attempts to create a human-readable string for any object.
Instance Method Details
#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.
24 25 26 27 28 29 30 31 32 33 |
# File 'app/helpers/active_admin/display_helper.rb', line 24 def display_name(resource) unless resource.nil? result = render_in_context(resource, display_name_method_for(resource)) if result.to_s&.strip&.present? ERB::Util.html_escape(result) else ERB::Util.html_escape(render_in_context(resource, DISPLAY_NAME_FALLBACK)) end end end |
#format_attribute(resource, attr) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/helpers/active_admin/display_helper.rb', line 35 def format_attribute(resource, attr) value = find_value resource, attr if value.is_a?(Arbre::Element) value elsif boolean_attr?(resource, attr, value) Arbre::Context.new { status_tag value } else pretty_format value end end |
#pretty_format(object) ⇒ Object
Attempts to create a human-readable string for any object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/helpers/active_admin/display_helper.rb', line 48 def pretty_format(object) case object when String, Numeric, Symbol, Arbre::Element object.to_s when Date, Time I18n.localize object, format: active_admin_application.localize_format when Array format_collection(object) else if defined?(::ActiveRecord) && object.is_a?(ActiveRecord::Base) || defined?(::Mongoid) && object.class.include?(Mongoid::Document) auto_link object elsif defined?(::ActiveRecord) && object.is_a?(ActiveRecord::Relation) format_collection(object) else display_name object end end end |