2015-05-28 13:20:14 +00:00
|
|
|
module ErrorsHelper
|
|
|
|
|
|
|
|
|
|
def simple_error(field, error_msg)
|
|
|
|
|
{"errors" => {field => [error_msg]}}
|
|
|
|
|
end
|
|
|
|
|
|
2021-03-13 06:10:47 +00:00
|
|
|
def errors_for(object)
|
|
|
|
|
if object.errors.any?
|
|
|
|
|
content_tag(:div, class: 'card text-white bg-danger mb-3') do
|
|
|
|
|
concat(content_tag(:div, class: 'card-header') do
|
|
|
|
|
concat(content_tag(:h4) do
|
|
|
|
|
concat "The form contains #{pluralize(object.errors.count, 'error')}:"
|
|
|
|
|
end)
|
|
|
|
|
end)
|
|
|
|
|
concat(content_tag(:div, class: 'card-body') do
|
|
|
|
|
concat(content_tag(:ul) do
|
|
|
|
|
object.errors.full_messages.each do |msg|
|
|
|
|
|
concat content_tag(:li, msg)
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2015-05-28 13:20:14 +00:00
|
|
|
end
|