Module: Manage::ApplicationHelper

Defined in:
app/helpers/manage/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#collection_table(collection, resource_class, no_items_text) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/manage/application_helper.rb', line 4

def collection_table collection, resource_class, no_items_text

  if collection.empty?
    return (:h3, resource_class.model_name.human(count: 2)) + (:p,  no_items_text)
  else
    rows = []

    ths = resource_class.attribute_names.collect do |attr|
      (:td, truncate(resource_class.human_attribute_name(attr).to_s, length: 50))
    end.join('').html_safe
    rows << (:tr, ths)

    collection.each do |item|
      tds = resource_class.attribute_names.collect do |attr|
        (:td, truncate(item.public_send(attr).to_s, length: 50))
      end.join('').html_safe

      rows << (:tr, tds)
    end
    (:h3, resource_class.model_name.human(count: 2)) +
    (:table, rows.join('').html_safe)
  end
end

#condensed_table(resource_class, cols = 2) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/helpers/manage/application_helper.rb', line 28

def condensed_table resource_class, cols=2
  rows = []
  resource_class.attribute_names.each_slice(cols).each do |slice|
    row = slice.collect do |attr|
      (:td, resource_class.human_attribute_name(attr)) +
      (:td, resource.public_send(attr))
    end
    rows << (:tr, row.join('').html_safe)
  end

   :table, rows.join('').html_safe
end