Module: Voom::Presenters::Helpers::Rails::ModelTable

Included in:
Voom::Presenters::Helpers::Rails
Defined in:
lib/voom/presenters/helpers/rails/model_table.rb

Instance Method Summary collapse

Instance Method Details

#table_for(query_, empty_icon: nil, except: [:id, :created_at, :updated_at], selectable: false, &block) ⇒ Object

Build a a table from a Rails model



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/voom/presenters/helpers/rails/model_table.rb', line 7

def table_for(query_,
              empty_icon: nil,
              except: [:id, :created_at, :updated_at],
              selectable: false, &block)
  row1 = query_.first
  if row1
    __columns__ = row1.class.columns
    table selectable: selectable do
      _table_header_(__columns__, except)

      query_.each do |item_|
        row do
          _table_row_(__columns__, block, except, item_)
        end
      end
    end
  else
    body "You have no #{query_.arel_table.name.pluralize}", level: 2
    icon empty_icon, size: '10rem' if empty_icon
  end
end