module Fend::Plugins::BaseErrors
`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).messages #=> { base: ["Invalid email or password"] }
You can specify custom key when loading the plugin:
plugin :base_errors, key: :general
Constants
- DEFAULT_KEY
Public Class Methods
configure(validation, opts = {})
click to toggle source
# 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