2016-04-05 01:25:38 +00:00
|
|
|
module FormHelper
|
|
|
|
def form_errors(model)
|
|
|
|
return unless model.errors.any?
|
|
|
|
|
|
|
|
pluralized = 'error'.pluralize(model.errors.count)
|
|
|
|
headline = "The form contains the following #{pluralized}:"
|
|
|
|
|
|
|
|
content_tag(:div, class: 'alert alert-danger', id: 'error_explanation') do
|
|
|
|
content_tag(:h4, headline) <<
|
2016-12-15 22:14:20 +00:00
|
|
|
content_tag(:ul) do
|
|
|
|
model.errors.full_messages.
|
|
|
|
map { |msg| content_tag(:li, msg) }.
|
|
|
|
join.
|
|
|
|
html_safe
|
|
|
|
end
|
2016-04-05 01:25:38 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|