Class: Snails::Form::Errors
- Defined in:
- runtime/snails/form/errors.rbs,
runtime/snails/form/errors.rb
Constant Summary collapse
- DEFAULT_MESSAGES =
The messages core ships for the built-in rule keys, so an app without
I18nstill answers real text and an app with one can override per form throughmessage_scope. { blank: "can't be blank", taken: "has already been taken", invalid: "is invalid", inclusion: "is not included in the list", exclusion: "is reserved", too_short: "is too short (minimum is %{count} characters)", too_long: "is too long (maximum is %{count} characters)", wrong_length: "is the wrong length (should be %{count} characters)", confirmation: "doesn't match %{attribute}", }
Instance Method Summary collapse
-
#add(attribute, message, **options) ⇒ void
append one error.
-
#any? ⇒ bool
at least one error recorded.
-
#empty? ⇒ bool
no errors recorded.
-
#full_messages ⇒ Array[String]
the display strings, in error order (the ordered list an HTTP 422 detail ships).
-
#initialize(form) ⇒ void
constructor
start the list on its owning form.
-
#join(separator = ", ") ⇒ String
full_messages.join: the one call a response body needs (errors.join("\n")). -
#on(attribute) ⇒ Array[String]
the raw (unprefixed) messages recorded for one attribute.
-
#size ⇒ Integer
how many errors are recorded.
Constructor Details
#initialize(form) ⇒ void
start the list on its owning form.
29 |
# File 'runtime/snails/form/errors.rb', line 29
def initialize: (Snails::Form form) -> void
|
Instance Method Details
#add(attribute, message, **options) ⇒ void
append one error. message is display text, or a Symbol key resolved
under the form's message scope; **options are interpolation values for
that message (count:, attribute:).
50 |
# File 'runtime/snails/form/errors.rb', line 50
def add: (untyped attribute, (String | Symbol) message, **untyped options) -> void
|
#any? ⇒ bool
at least one error recorded.
89 |
# File 'runtime/snails/form/errors.rb', line 89
def any?: () -> bool
|
#empty? ⇒ bool
no errors recorded.
82 |
# File 'runtime/snails/form/errors.rb', line 82
def empty?: () -> bool
|
#full_messages ⇒ Array[String]
the display strings, in error order (the ordered list an HTTP 422 detail ships).
66 |
# File 'runtime/snails/form/errors.rb', line 66
def full_messages: () -> Array[String]
|
#join(separator = ", ") ⇒ String
full_messages.join: the one call a response body needs
(errors.join("\n")).
75 |
# File 'runtime/snails/form/errors.rb', line 75
def join: (?String separator) -> String
|
#on(attribute) ⇒ Array[String]
the raw (unprefixed) messages recorded for one attribute. A non-Symbol name is a caller bug: it would answer an empty list for a field that does have messages, so the entry guard is loud here as well.
107 |
# File 'runtime/snails/form/errors.rb', line 107
def on: (untyped attribute) -> Array[String]
|
#size ⇒ Integer
how many errors are recorded.
96 |
# File 'runtime/snails/form/errors.rb', line 96
def size: () -> Integer
|