Module: ActionTable::Helper

Defined in:
lib/action_table/helper.rb

Instance Method Summary collapse

Instance Method Details

#action_table(records, fields, paginate: false, links: ActionTable.config.links, actions: ActionTable.config.actions, styles: ActionTable.config.styles) ⇒ String

Renders an ActiveRecord collection as a HTML table.

Parameters:

  • records (ActiveRecord::Collection)

    ActiveRecord collection to render

  • table (Array<String>, Array<Symbol>)

    columns (must map to methods on each ActiveRecord instance)

  • styles (Array<String>, Array<Symbol>) (defaults to: ActionTable.config.styles)

    no, one or many of bootstrap table styles (table- prefix will be added)

  • link (String, Symbol, Array<String>, Array<Symbol>)

    field(s) that will link to the resource

  • paginate (true, false) (defaults to: false)

    whether to render pagination links (default: false)

  • actions (Array<String>, Array<Symbol>) (defaults to: ActionTable.config.actions)

    render action lins (show, edit and delete)

Returns:

  • (String)

    returns a HTML string representing the ActiveRecord collection.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/action_table/helper.rb', line 22

def action_table(
  records,
  fields,
  paginate: false,
  links: ActionTable.config.links,
  actions: ActionTable.config.actions,
  styles: ActionTable.config.styles
)
  action_table = View.new(
    columns: fields,
    records: records,
    paginate: paginate,
    links: links,
    actions: actions,
  )

  styles = BootstrapStyles.new(styles)
  render('action_table/table', table: action_table, styles: styles)
end