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
# 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)
  @table = table
  build_colgroups
  rows(*attrs)
end

#row(*args, &block) ⇒ Object



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

def row(*args, &block)
  title = args[0]
  options = args.extract_options!
  classes = [:row]
  if options[:class]
    classes << options[:class]
  elsif title.present?
    classes << "row-#{title.to_s.parameterize(separator: "_")}"
  end
  options[:class] = classes.join(" ")

  @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



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

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