'How to create an inline validation

Is there a way to create inline validations in Rails? For example convert this

class Invoice < ApplicationRecord
  validate :active_customer

  def active_customer
    errors.add(:customer_id, "is not active") unless customer.active?
  end
end

to something like this

class Invoice < ApplicationRecord
  validate { errors.add(:customer_id, "is not active") unless customer.active? }
end


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source