Module: Merb::Helpers::Form::Builder::Errorifier

Included in:
FormWithErrors, ResourcefulFormWithErrors
Defined in:
lib/merb-helpers/form/builder.rb

Instance Method Summary collapse

Instance Method Details

#error_messages_for(obj, error_class, build_li, header, before) ⇒ Object



404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'lib/merb-helpers/form/builder.rb', line 404

def error_messages_for(obj, error_class, build_li, header, before)
  obj ||= @obj
  return "" unless obj.respond_to?(:errors)

  errors = obj.errors

  return "" if errors.empty?

  header_message = header % [errors.size, errors.size == 1 ? "" : "s"]
  markup = %Q{<div class='#{error_class}'>#{header_message}<ul>}
  errors.each {|err| markup << (build_li % err.join(" "))}
  markup << %Q{</ul></div>}
end