Module: Utilities::PageHelper

Includes:
IconHelper
Included in:
BaseEditingHelper, SearchHelper
Defined in:
app/helpers/utilities/page_helper.rb

Instance Method Summary collapse

Methods included from IconHelper

#icon

Instance Method Details

#boolean_to_icon(valore) ⇒ Object

Parameters:

  • valore (TrueClass, FalseClass, NilClass)


38
39
40
41
42
43
44
45
46
47
# File 'app/helpers/utilities/page_helper.rb', line 38

def boolean_to_icon(valore)
  case valore
  when true
    icon("check-lg", class: "text-success")
  when false
    icon("x-lg", class: "text-danger")
  else
    nil
  end
end

#error_messages_for(obj, field) ⇒ Object

Parameters:

  • obj (BaseModel)

    instance

  • field (Symbol)


58
59
60
61
62
63
# File 'app/helpers/utilities/page_helper.rb', line 58

def error_messages_for(obj, field)
  if obj.errors.include?(field)
    msg = obj.errors.full_messages_for(field).join(",")
    (:div, icon("x-circle-fill", msg), class: "invalid-feedback")
  end
end

#new_button(path, options = {}) ⇒ Object

Parameters:

  • path (String)
  • options (Hash) (defaults to: {})


51
52
53
54
# File 'app/helpers/utilities/page_helper.rb', line 51

def new_button(path, options = {})
  options.merge!({class: 'btn btn-success btn-sm'})
  link_to icon("plus-lg", I18n.t(:new)), path, options
end

#title_mod_g(base_class) ⇒ Object

Traduzione del titolo EDIT con possibilità di modificare intestazione rispetto a modello

  • Il default è quello di Utilizzare la chiave .edit

  • Viene cercato la traduzione con la chiave titles.CHIAVE_I18N_MODELLO.edit

Parameters:

  • base_class (BaseModel)


9
10
11
# File 'app/helpers/utilities/page_helper.rb', line 9

def title_mod_g(base_class)
  "#{t("titles.#{base_class.model_name.i18n_key}.edit", default: :edit)} #{base_class.model_name.human}"
end

#title_new_g(base_class) ⇒ Object

Traduzione del titolo NUOVO con possibilità di modificare intestazione rispetto a modello

  • Il default è quello di Utilizzare la chiave .new

  • Viene cercato la traduzione con la chiave titles.CHIAVE_I18N_MODELLO.new

Parameters:

  • base_class (BaseModel)


18
19
20
# File 'app/helpers/utilities/page_helper.rb', line 18

def title_new_g(base_class)
  "#{t("titles.#{base_class.model_name.i18n_key}.new", default: :new)} #{base_class.model_name.human}"
end