Module: LinksHelper

Defined in:
app/helpers/links_helper.rb

Instance Method Summary collapse

Instance Method Details



55
56
57
58
# File 'app/helpers/links_helper.rb', line 55

def link_to_back(url, html_options = {})
  html_options.reverse_merge!(class: 'btn btn-default')
  link_to t('back'), url, html_options
end


42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/helpers/links_helper.rb', line 42

def link_to_destroy(model, url, html_options = {})
  button_class = 'btn btn-danger glyphicon glyphicon-trash'
  html_options.reverse_merge!({class: button_class, "data-target" => "#delete-confirmation", "data-toggle" => "modal"})
  authorized = authorize_button :destroy, model, html_options, button_class if model.present?
  if authorized
    link_to '', url, html_options
  else
    (:div, class: 'tooltip-wrapper', "data-title" => I18n.t('not_authorized')) do
      link_to t('destroy'), url, html_options
    end
  end
end


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

def link_to_edit(model, url, html_options = {})
  button_class = 'btn btn-default btn-sm'
  html_options.reverse_merge!(class: button_class)
  authorized = authorize_button :update, model, html_options, button_class if model.present?
  if authorized
    link_to t('edit'), url, html_options
  else
    (:div, class: 'tooltip-wrapper', "data-title" => I18n.t('not_authorized')) do
      link_to t('edit'), url, html_options
    end
  end
end


60
61
62
# File 'app/helpers/links_helper.rb', line 60

def link_to_menu(model, url)
  link_to model.model_name.human.pluralize, url
end


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

def link_to_new(model, url, html_options = {})
  button_class = 'btn btn-default btn-lg'
  html_options.reverse_merge!(class: button_class)
  authorized = authorize_button :create, model, html_options, button_class if model.present?
  if authorized
    link_to t('new', model: model.model_name.human), url, html_options
  else
    (:div, class: 'tooltip-wrapper', "data-title" => I18n.t('not_authorized')) do
      link_to t('new', model: model.model_name.human), url, html_options
    end
  end
end


29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/links_helper.rb', line 29

def link_to_show(model, url, html_options = {})
  button_class = 'btn btn-default btn-sm'
  html_options.reverse_merge!(class: button_class)
  authorized = authorize_button :read, model, html_options, button_class if model.present?
  if authorized
    link_to t('show'), url, html_options
  else
    (:div, class: 'tooltip-wrapper', "data-title" => I18n.t('not_authorized')) do
      link_to t('show'), url, html_options
    end
  end
end

#submit_button(form, value = nil) ⇒ Object



72
73
74
75
76
77
78
# File 'app/helpers/links_helper.rb', line 72

def submit_button(form, value = nil)
  if value
    form.submit value, class: "btn btn-primary btn-lg"
  else
    form.submit t('save'), class: "btn btn-primary btn-lg"
  end
end

#submit_or_edit_button(form, edit_path, is_edition) ⇒ Object



64
65
66
67
68
69
70
# File 'app/helpers/links_helper.rb', line 64

def submit_or_edit_button(form, edit_path, is_edition)
  if is_edition && params[:action] != 'new'
    link_to_edit form.object, edit_path, class: "btn btn-primary btn-lg"
  else
    submit_button(form)
  end
end