Module: Padrino::Helpers::FormHelpers::Errors


Helpers to generate form errors.

Instance Method Summary

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.


# => <span class="error">can't be blank</div>
error_message_on :post, :title
error_message_on @post, :title

# => <div class="custom" style="border:1px solid red">can't be blank</div>
error_message_on :post, :title, :tag => :id, :class => :custom, :style => "border:1px solid red"

# => <div class="error">This title can't be blank (or it won't work)</div>
error_message_on :post, :title, :prepend => "This title", :append => "(or it won't work)"

Options Hash (options):

  • :tag (String) — default: "span" — The tag that encloses the error.
  • :prepend (String) — default: "" — The text to prepend before the field error.
  • :append (String) — default: "" — The text to append after the field error.

#error_messages_for(*objects, options = {}) ⇒ String

Constructs list HTML for the errors for a given symbol.


error_messages_for :user

Options Hash (options):

  • :header_tag (String) — default: "h2" — Used for the header of the error div.
  • :id (String) — default: "field-errors" — The id of the error div.
  • :class (String) — default: "field-errors" — The class of the error div.
  • :object (Array<Object>) — The object (or array of objects) for which to display errors, if you need to escape the instance variable convention.
  • :object_name (String) — The object name to use in the header, or any text that you prefer. If :object_name is not set, the name of the first object will be used.
  • :header_message (String) — default: "X errors prohibited this object from being saved" — The message in the header of the error div. Pass nil or an empty string to avoid the header message altogether.
  • :message (String) — default: "There were problems with the following fields:" — The explanation message after the header message and before the error list. Pass nil or an empty string to avoid the explanation message altogether.