Module: FormHelper

Defined in:
app/helpers/form_helper.rb

Instance Method Summary collapse

Instance Method Details

#form_errors(model) ⇒ Object


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/helpers/form_helper.rb', line 2

def form_errors(model)
  return unless model.errors.any?

  pluralized = 'error'.pluralize(model.errors.count)
  headline   = "The form contains the following #{pluralized}:"

  (:div, class: 'alert alert-danger', id: 'error_explanation') do
    (:h4, headline) <<
    (:ul) do
      model.errors.full_messages.
        map { |msg| (:li, msg) }.
        join.
        html_safe
    end
  end
end