Module: EacRailsUtils::LinksHelper

Defined in:
app/helpers/eac_rails_utils/links_helper.rb

Instance Method Summary collapse

Instance Method Details

#object_path(object, action = nil) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/helpers/eac_rails_utils/links_helper.rb', line 37

def object_path(object, action = nil)
  current_class = object_class(object)
  tried_paths = []
  while current_class
    path = object_path_by_class(current_class, action)
    return send(path, object) if respond_to?(path)

    tried_paths << path
    current_class = current_class.superclass
  end
  raise "Path not found for {object: #{object.class}, action: \"#{action}\"}" \
    "(Tried: #{tried_paths})"
end


5
6
7
8
9
10
11
12
13
# File 'app/helpers/eac_rails_utils/links_helper.rb', line 5

def short_delete_link(object)
  short_object_link object, '', class: 'delete_link', method: :delete, target: '_blank',
                                title: ::I18n.t('eac_rails_utils.links.delete_object',
                                                label: object.to_s),
                                data: {
                                  confirm: ::I18n.t('eac_rails_utils.links.delete_confirm',
                                                    label: object.to_s)
                                }
end


33
34
35
# File 'app/helpers/eac_rails_utils/links_helper.rb', line 33

def short_detail_link(object)
  short_detail_show_link(object, true)
end


15
16
17
18
19
# File 'app/helpers/eac_rails_utils/links_helper.rb', line 15

def short_edit_link(object)
  short_object_link object, 'edit', class: 'edit_link', target: '_blank',
                                    title: ::I18n.t('eac_rails_utils.links.edit_object',
                                                    label: object.to_s)
end


21
22
23
24
25
26
27
# File 'app/helpers/eac_rails_utils/links_helper.rb', line 21

def short_goto_link(url)
  value_or_sign(url, '') do |value|
    link_to '', value, class: 'goto_link', target: '_blank',
                       title: ::I18n.t('eac_rails_utils.links.goto_url', url: value.to_s),
                       rel: 'noopener'
  end
end


29
30
31
# File 'app/helpers/eac_rails_utils/links_helper.rb', line 29

def short_show_link(object)
  short_detail_show_link(object, false)
end