Module: TableForPatch

Included in:
ActiveAdmin::Views::TableFor
Defined in:
lib/activeadmin_custom_layout/layout/components/table_for.rb

Instance Method Summary collapse

Instance Method Details

#column(*args, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/activeadmin_custom_layout/layout/components/table_for.rb', line 3

def column(*args, &block)
  super

  col = @columns.last

  @collection.each_with_index do |resource, index|
    data = aa_data[:table][:rows][index][:data] ||= []

    attr = col.data
    attr = args[1][:sortable] if args[1] and args[1][:sortable].present?

    data << {
      classes: col.html_class,
      html: "#{find_last_child(@tbody.children[index].children.last)}",
      value: "#{find_value_patch(resource, attr)}"
    }
  end
end

#find_last_child(elem) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/activeadmin_custom_layout/layout/components/table_for.rb', line 22

def find_last_child(elem)
  if elem.children.length>0
    find_last_child(elem.children.first)
  else
    elem
  end
end

#find_value_patch(resource, attr) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/activeadmin_custom_layout/layout/components/table_for.rb', line 30

def find_value_patch(resource, attr)
  if attr.is_a? Proc
    nil
  elsif attr =~ /\A(.+)_id\z/ && reflection_for(resource, $1.to_sym)
    resource.public_send $1
  elsif resource.respond_to? attr
    resource.public_send attr
  elsif resource.respond_to? :[]
    resource[attr]
  end
end