Is it possible to validate the field of another table that is related in a specific model?
For example, I need to validate an email field in a Orders table, but only emails from an internal user (which is in a Users table) . That is, who is an internal user should enter his email. This information comes from login (devise), that is, from another table (requests belongs_to
user).
In this, in the requests model, I'm creating a validation def like this:
def valida_email_interno
errors.add(:email, "Digite o email") if email.blank? and ...# a condição que o usuario é interno, por exemplo, @pedido.user.localpedido == 1
Any ideas?