AE
Ash Elixir•3y ago
axdc

passing actor when using AshPhoenix.Form.submit

I've been reading the policy guide and docs and I've got them up and running for all my read actions, but when submitting a create or update using AshPhoenix.Form I'm not sure where exactly to provide the actor. Is there a different way this is meant to be done?
5 Replies
sevenseacat
sevenseacat•3y ago
if you're calling AshPhoenix.Form.submit, it can be supplied as an API option, eg. AshPhoenix.Form.submit(socket.assigns.form, api_opts: [actor: socket.assigns.current_user])
ZachDaniel
ZachDaniel•3y ago
You can do it there, but the better place would be
AshPhoenix.Form.for_create(..., actor: actor)
AshPhoenix.Form.for_create(..., actor: actor)
Also thanks to @sevenseacat for rewriting the bulk of the policies guide to make it more accessible and understandable 🙇
sevenseacat
sevenseacat•3y ago
Ooh I didn’t know that one
axdc
axdcOP•3y ago
Got it! So the actor is given to the form at creation and is already there for the submit. And yes, the policy guide is very thorough and readable, thank you @Rebecca Le 😊
ZachDaniel
ZachDaniel•3y ago
Yep!

Did you find this page helpful?