Module: Fend::Plugins::BaseErrors
- Defined in:
- lib/fend/plugins/base_errors.rb
Overview
‘base_errors` plugin allows you to add validation errors which are not related to a specific param, but to validation input as a whole.
class AuthValidation < Fend
plugin :base_errors
validate do |i|
i.params(:email, :password) do |email, password|
# ...
if email.invalid? || password.invalid?
add_base_error("Invalid email or password")
end
end
end
end
Messages are available under ‘:base` key by default.
AuthValidation.call(email: nil, password: nil).
#=> { base: ["Invalid email or password"] }
You can specify custom key when loading the plugin:
plugin :base_errors, key: :general
Defined Under Namespace
Modules: InstanceMethods
Constant Summary collapse
- DEFAULT_KEY =
:base
Class Method Summary collapse
Class Method Details
.configure(validation, opts = {}) ⇒ Object
33 34 35 |
# File 'lib/fend/plugins/base_errors.rb', line 33 def self.configure(validation, opts = {}) validation.opts[:base_errors_key] = opts[:key] || validation.opts[:base_errors_key] || DEFAULT_KEY end |