How to fetch the actor inside validations?
Basically I'm creating a validation that needs to actor to call another api, but the input changeset doesn't contain the actor.
6 Replies
You can't access the actor inside of validations
If you want to use the actor, use a
change
, i.e
Oh, that's a bummer. I will use the change then, but it does seem like a hack
What do you need the current user in a validation for?
If you need access to the current user, you probably want a policy check
I want to convert this policy to a validation:
As you can see, I just need to actor so I can call that
get
function from another resourceCan you pass
authorize?: false, actor: nil
instead?
You don't really want to get the "property that the actor can see" which is what you're doing by providing the actor there
Either way: validations are made for "lightweight input validation"
If you need to do database queries, you should do it in a change and use a before_action
hookGot it! I was able to remove the actor in the end