Module: FormErrorsHelper

Defined in:
app/helpers/form_errors_helper.rb

Instance Method Summary collapse

Instance Method Details

#error_detailsObject



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

def error_details
  return unless object.respond_to?(:errors) && object.errors.any?

  messages = object.errors.full_messages.map { |msg| @template.(:li, msg) }.join

  @template. :ul, class: 'my-0' do
    messages.html_safe
  end
end

#error_messages_for(attribute) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/form_errors_helper.rb', line 25

def error_messages_for(attribute)
  return unless object.respond_to?(:errors) && object.errors.any?

  error_messages = object.errors[attribute]

  @template. :div, class: 'alert alert-danger' do
    @template.fa_icon_tag('remove') + ' ' +
      error_messages.map { |message| object.errors.full_message(attribute, message) }.to_sentence
  end
end

#error_notificationObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/form_errors_helper.rb', line 3

def error_notification
  return unless object.respond_to?(:errors) && object.errors.any?

  error_count = object.errors.count
  humanized_name = I18n.t("activerecord.models.#{object_name.to_s.downcase}.one",
                          default: object_name.to_s.humanize)

  default_error_message = "#{@template.pluralize(error_count, 'errors')} prohibited this #{humanized_name} from being saved."
  error_message = I18n.t('activerecord.errors.template.header',
                         count: error_count,
                         model: humanized_name,
                         default: default_error_message)

  @template. :div, class: 'alert alert-danger' do
    @template.fa_icon_tag('remove') + ' ' +
      error_message +
      error_details
  end
end