Module: MyHelper

Defined in:
app/helpers/my_helper.rb

Overview

Helper methods for user context

Instance Method Summary collapse

Instance Method Details

#my_destroy_icon(entity, options = {}) ⇒ Object

Parameters:

  • entity (ApplicationRecord)
  • options (Hash) (defaults to: {})


16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/my_helper.rb', line 16

def my_destroy_icon(entity, options = {})
  title = options.delete(:title) { t(:edit) }
  key = entity.respond_to?(:uuid) ? entity.uuid : entity.id
  path = "/my/#{entity.class.table_name}/#{key}"
  default = {
    class: 'danger',
    data: { confirm: t(:are_you_sure) },
    method: :delete,
  }
  my_icon_with_link('biovision/icons/destroy.svg', path, title.to_s, default.merge(options))
end

#my_edit_icon(entity, options = {}) ⇒ Object

Parameters:

  • entity (ApplicationRecord)
  • options (Hash) (defaults to: {})


7
8
9
10
11
12
# File 'app/helpers/my_helper.rb', line 7

def my_edit_icon(entity, options = {})
  title = options.delete(:title) { t(:edit) }
  key = entity.respond_to?(:uuid) ? entity.uuid : entity.id
  path = "/my/#{entity.class.table_name}/#{key}/edit"
  my_icon_with_link('biovision/icons/edit.svg', path, title.to_s, options)
end

Parameters:

  • path (String|ApplicationRecord)
  • title (String) (defaults to: '')
  • options (Hash) (defaults to: {})


31
32
33
# File 'app/helpers/my_helper.rb', line 31

def my_icon_with_link(source, path, title = '', options = {})
  link_to(image_tag(source, alt: title), path, options)
end