Module: Padrino::Helpers::FormHelpers::Errors
- Defined in:
- padrino-helpers/lib/padrino-helpers/form_helpers/errors.rb
Overview
Helpers to generate form errors.
Instance Method Summary collapse
-
#error_message_on(object, field, options = {}) ⇒ String
Returns a string containing the error message attached to the
method
on theobject
if one exists. -
#error_messages_for(*objects, options = {}) ⇒ String
Constructs list HTML for the errors for a given symbol.
Instance Method Details
#error_message_on(object, field, options = {}) ⇒ String
Returns a string containing the error message attached to the method
on the object
if one exists.
79 80 81 82 83 84 85 86 |
# File 'padrino-helpers/lib/padrino-helpers/form_helpers/errors.rb', line 79 def (object, field, ={}) error = Array(resolve_object(object).errors[field]).first return SafeBuffer.new unless error = { :tag => :span, :class => :error }.update() tag = .delete(:tag) error = [.delete(:prepend), error, .delete(:append)].compact.join(" ") content_tag(tag, error, ) end |
#error_messages_for(*objects, options = {}) ⇒ String
Constructs list HTML for the errors for a given symbol.
39 40 41 42 43 44 45 46 |
# File 'padrino-helpers/lib/padrino-helpers/form_helpers/errors.rb', line 39 def (*objects) = objects.last.is_a?(Hash) ? Utils.symbolize_keys(objects.pop) : {} objects = objects.map{ |obj| resolve_object(obj) }.compact count = objects.inject(0){ |sum, object| sum + object.errors.count } return SafeBuffer.new if count.zero? content_tag(:div, error_contents(objects, count, ), error_html_attributes()) end |