Module: Admin::Resources::DisplayHelper

Defined in:
app/helpers/admin/resources/display_helper.rb

Instance Method Summary collapse

Instance Method Details

#build_display(item, fields) ⇒ Object



7
8
9
10
11
12
13
# File 'app/helpers/admin/resources/display_helper.rb', line 7

def build_display(item, fields)
  fields.map do |attribute, type|
    condition = (type == :boolean) || item.send(attribute).present?
    value = condition ? send("display_#{type}", item, attribute) : mdash
    [@resource.human_attribute_name(attribute), value]
  end
end

#mdashObject



3
4
5
# File 'app/helpers/admin/resources/display_helper.rb', line 3

def mdash
  "—".html_safe
end

#typus_relationshipsObject



15
16
17
18
19
20
21
22
23
24
25
# File 'app/helpers/admin/resources/display_helper.rb', line 15

def typus_relationships
  String.new.tap do |html|
    @resource.typus_defaults_for(:relationships).each do |relationship|
      association = @resource.reflect_on_association(relationship.to_sym)
      macro, klass = association.macro, association.class_name.constantize
      if [:has_many, :has_one].include?(macro) && admin_user.can?('read', klass)
        html << send("typus_form_#{macro}", relationship)
      end
    end
  end.html_safe
end