Class: ActiveAdmin::Views::AttributesTable

Inherits:
Component
  • Object
show all
Defined in:
lib/active_admin/views/components/attributes_table.rb

Instance Method Summary collapse

Instance Method Details

#build(obj, *attrs) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/active_admin/views/components/attributes_table.rb', line 8

def build(obj, *attrs)
  @collection = Array.wrap(obj)
  @resource_class = @collection.first.class
  options = {}
  options[:for] = @collection.first if single_record?
  super(options)
  add_class "attributes-table"
  @table = table
  build_colgroups
  rows(*attrs)
end

#row(*args, &block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/active_admin/views/components/attributes_table.rb', line 24

def row(*args, &block)
  title = args[0]
  options = args.extract_options!
  options["data-row"] = title.to_s.parameterize(separator: "_") if title.present?

  @table << tr(options) do
    th do
      header_content_for(title)
    end
    @collection.each do |record|
      td do
        content_for(record, block || title)
      end
    end
  end
end

#rows(*attrs) ⇒ Object



20
21
22
# File 'lib/active_admin/views/components/attributes_table.rb', line 20

def rows(*attrs)
  attrs.each { |attr| row(attr) }
end