Module: Spotlight::CrudLinkHelpers

Included in:
ApplicationHelper
Defined in:
app/helpers/spotlight/crud_link_helpers.rb

Overview

Helpers for building polymorphic links within the exhibit context

Instance Method Summary collapse

Instance Method Details

#action_label(model, action) ⇒ Object



61
62
63
# File 'app/helpers/spotlight/crud_link_helpers.rb', line 61

def action_label(model, action)
  action_default_value model, action
end


7
8
9
# File 'app/helpers/spotlight/crud_link_helpers.rb', line 7

def cancel_link(model, link, link_to_options = {})
  link_to action_default_value(model, :cancel), link, link_to_options
end


23
24
25
26
27
# File 'app/helpers/spotlight/crud_link_helpers.rb', line 23

def create_link(model, *args)
  link_to_options = args.extract_options!
  link = args.first || polymorphic_path([spotlight, model], action: :new)
  link_to action_default_value(model), link, link_to_options
end


47
48
49
50
51
52
# File 'app/helpers/spotlight/crud_link_helpers.rb', line 47

def delete_link(model, *args)
  link_to_options = args.extract_options!
  link = args.first || [spotlight, model]
  default_options = { method: :delete, data: { confirm: action_default_value(model, :destroy_are_you_sure) } }
  link_to action_default_value(model, :destroy), link, default_options.merge(link_to_options)
end


35
36
37
38
39
# File 'app/helpers/spotlight/crud_link_helpers.rb', line 35

def edit_link(model, *args)
  link_to_options = args.extract_options!
  link = args.first || polymorphic_path([spotlight, model], action: :edit)
  link_to action_default_value(model), link, link_to_options
end


29
30
31
32
33
# File 'app/helpers/spotlight/crud_link_helpers.rb', line 29

def exhibit_create_link(model, *args)
  link_to_options = args.extract_options!
  link = args.first || polymorphic_path([spotlight, current_exhibit, model], action: :new)
  link_to action_default_value(model), link, link_to_options
end


54
55
56
57
58
59
# File 'app/helpers/spotlight/crud_link_helpers.rb', line 54

def exhibit_delete_link(model, *args)
  link_to_options = args.extract_options!
  link = args.first || [spotlight, model.exhibit, model]
  default_options = { method: :delete, data: { confirm: action_default_value(model, :destroy_are_you_sure) } }
  link_to action_default_value(model, :destroy), link, default_options.merge(link_to_options)
end


41
42
43
44
45
# File 'app/helpers/spotlight/crud_link_helpers.rb', line 41

def exhibit_edit_link(model, *args)
  link_to_options = args.extract_options!
  link = args.first || polymorphic_path([spotlight, model.exhibit, model], action: :edit)
  link_to action_default_value(model), link, link_to_options
end


17
18
19
20
21
# File 'app/helpers/spotlight/crud_link_helpers.rb', line 17

def exhibit_view_link(model, *args)
  link_to_options = args.extract_options!
  link = args.first || [spotlight, model.exhibit, model]
  link_to action_default_value(model, :view), link, link_to_options
end


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/helpers/spotlight/crud_link_helpers.rb', line 65

def nav_link(name = nil, options = nil, html_options = nil, &block)
  # rubocop:disable Style/ParallelAssignment
  # (Note: this is copied from upstream in Rails)
  html_options, options, name = options, name, block if block_given?
  # rubocop:enable Style/ParallelAssignment

  html_options ||= {}

  (:li, class: 'nav-item') do
    if block_given?
      link_to(options, nav_link_html_options(options, html_options), &block)
    else
      link_to(name, options, nav_link_html_options(options, html_options), &block)
    end
  end
end


11
12
13
14
15
# File 'app/helpers/spotlight/crud_link_helpers.rb', line 11

def view_link(model, *args)
  link_to_options = args.extract_options!
  link = args.first || [spotlight, model]
  link_to action_default_value(model, :view), link, link_to_options
end