Module: AuxiliaryRails::ViewHelpers::DisplayHelper

Included in:
AuxiliaryRails::ViewHelpers
Defined in:
lib/auxiliary_rails/view_helpers/display_helper.rb

Constant Summary collapse

DISPLAY_NAME_METHODS =
%i[
  display_name
  name
  title
  full_name
  username
  email
].freeze

Instance Method Summary collapse

Instance Method Details

#display_name(resource) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/auxiliary_rails/view_helpers/display_helper.rb', line 13

def display_name(resource)
  return if resource.nil?

  DISPLAY_NAME_METHODS.each do |method_name|
    if resource.respond_to?(method_name)
      return resource.public_send(method_name)
    end
  end

  if resource.respond_to?(:model_name) && resource.respond_to?(:id)
    return "#{resource.model_name.human} ##{resource.id}"
  end

  resource.to_s
end