Module: ActionTable::Helper

Defined in:
lib/action_table/helper.rb

Instance Method Summary collapse

Instance Method Details

#action_table(records, fields, paginate: false, link: ActionTable.config.link_method, 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 (Symbol) (defaults to: ActionTable.config.link_method)

    method name for the default name to use for anchor-tags

  • 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,
  link: ActionTable.config.link_method,
  actions: ActionTable.config.actions,
  styles: ActionTable.config.styles
)
  action_table = View.new(
    cols: fields,
    records: records,
    paginate: paginate,
    link: link,
    actions: actions,
    styles: styles,
  )

  render('action_table/table', table: action_table)
end