Module: ActionsHelper
- Defined in:
- app/helpers/actions_helper.rb
Overview
Helpers to create action links. This default implementation supports regular links with an icon and a label. To change the general style of action links, change the method #action_link, e.g. to generate a button. The common crud actions show, edit, destroy, index and add are provided here.
Instance Method Summary collapse
-
#action_icon(icon, label = nil) ⇒ Object
Outputs an icon for an action with an optional label.
-
#action_link(label, icon = nil, url = {}, html_options = {}) ⇒ Object
A generic helper method to create action links.
-
#add_action_link(path = nil, url_options = {}) ⇒ Object
Standard add action to given path.
-
#destroy_action_link(path = nil) ⇒ Object
Standard destroy action to the given path.
-
#edit_action_link(path = nil) ⇒ Object
Standard edit action to given path.
-
#index_action_link(path = nil, url_options = { returning: true }) ⇒ Object
Standard list action to the given path.
-
#show_action_link(path = nil) ⇒ Object
Standard show action to the given path.
Instance Method Details
#action_icon(icon, label = nil) ⇒ Object
Outputs an icon for an action with an optional label.
16 17 18 19 20 |
# File 'app/helpers/actions_helper.rb', line 16 def action_icon(icon, label = nil) html = tag.i('', class: "bi-#{icon}") html << ' ' << label if label html end |
#action_link(label, icon = nil, url = {}, html_options = {}) ⇒ Object
A generic helper method to create action links. These link could be styled to look like buttons, for example.
9 10 11 12 13 |
# File 'app/helpers/actions_helper.rb', line 9 def action_link(label, icon = nil, url = {}, = {}) add_css_class , 'action btn btn-light' link_to(icon ? action_icon(icon, label) : label, url, ) end |
#add_action_link(path = nil, url_options = {}) ⇒ Object
Standard add action to given path. Uses the current model_class
if no path is given.
56 57 58 59 60 |
# File 'app/helpers/actions_helper.rb', line 56 def add_action_link(path = nil, = {}) path ||= path_args(model_class) path = new_polymorphic_path(path, ) unless path.is_a?(String) action_link(ti('link.add'), 'plus', path) end |
#destroy_action_link(path = nil) ⇒ Object
Standard destroy action to the given path. Uses the current entry
if no path is given.
39 40 41 42 43 44 |
# File 'app/helpers/actions_helper.rb', line 39 def destroy_action_link(path = nil) path ||= path_args(entry) action_link(ti('link.delete'), 'trash', path, data: { 'turbo-confirm': ti(:confirm_delete), 'turbo-method': :delete }) end |
#edit_action_link(path = nil) ⇒ Object
Standard edit action to given path. Uses the current entry
if no path is given.
31 32 33 34 35 |
# File 'app/helpers/actions_helper.rb', line 31 def edit_action_link(path = nil) path ||= path_args(entry) path = edit_polymorphic_path(path) unless path.is_a?(String) action_link(ti('link.edit'), 'pencil', path) end |
#index_action_link(path = nil, url_options = { returning: true }) ⇒ Object
Standard list action to the given path. Uses the current model_class
if no path is given.
48 49 50 51 52 |
# File 'app/helpers/actions_helper.rb', line 48 def index_action_link(path = nil, = { returning: true }) path ||= path_args(model_class) path = polymorphic_path(path, ) unless path.is_a?(String) action_link(ti('link.list'), 'list', path) end |
#show_action_link(path = nil) ⇒ Object
Standard show action to the given path. Uses the current entry
if no path is given.
24 25 26 27 |
# File 'app/helpers/actions_helper.rb', line 24 def show_action_link(path = nil) path ||= path_args(entry) action_link(ti('link.show'), 'zoom-in', path) end |