Module: DryCrud::Table::Actions

Extended by:
ActiveSupport::Concern
Included in:
Builder
Defined in:
app/helpers/dry_crud/table/actions.rb

Overview

Adds action columns to the table builder. Predefined actions are available for show, edit and destroy. Additionally, a special col type to define cells linked to the show page of the row entry is provided.

Instance Method Summary collapse

Instance Method Details

#action_col(&block) ⇒ Object

Action column inside a table. No header. The cell content should be defined in the passed block.



72
73
74
# File 'app/helpers/dry_crud/table/actions.rb', line 72

def action_col(&block)
  col('', class: 'action', &block)
end

Renders the passed attr with a link to the show action for the current entry. A block may be given to define the link path for the row entry.



20
21
22
23
24
# File 'app/helpers/dry_crud/table/actions.rb', line 20

def attr_with_show_link(attr, &block)
  sortable_attr(attr) do |entry|
    link_to(format_attr(entry, attr), action_path(entry, &block))
  end
end

#destroy_action_col(**html_options, &block) ⇒ Object

Action column to destroy the row entry. A block may be given to define the link path for the row entry. If the block returns nil, no link is rendered.



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/helpers/dry_crud/table/actions.rb', line 56

def destroy_action_col(**html_options, &block)
  action_col do |entry|
    path = action_path(entry, &block)
    if path
      table_action_link('trash',
                        path,
                        **html_options.merge(
                          data: { 'turbo-confirm': ti(:confirm_delete),
                                  'turbo-method': :delete }
                        ))
    end
  end
end

#edit_action_col(**html_options, &block) ⇒ Object

Action column to edit the row entry. A block may be given to define the link path for the row entry. If the block returns nil, no link is rendered.



43
44
45
46
47
48
49
50
51
# File 'app/helpers/dry_crud/table/actions.rb', line 43

def edit_action_col(**html_options, &block)
  action_col do |entry|
    path = action_path(entry, &block)
    if path
      path = edit_polymorphic_path(path) unless path.is_a?(String)
      table_action_link('pencil', path, **html_options.clone)
    end
  end
end

#show_action_col(**html_options, &block) ⇒ Object

Action column to show the row entry. A block may be given to define the link path for the row entry. If the block returns nil, no link is rendered.



29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/dry_crud/table/actions.rb', line 29

def show_action_col(**html_options, &block)
  action_col do |entry|
    path = action_path(entry, &block)
    if path
      table_action_link('zoom-in',
                        path,
                        **html_options.clone)
    end
  end
end

Generic action link inside a table.



77
78
79
80
# File 'app/helpers/dry_crud/table/actions.rb', line 77

def table_action_link(icon, url, **html_options)
  add_css_class(html_options, "bi-#{icon}")
  link_to('', url, html_options)
end