clifinger
How to define custom actions
Hello,
I need Help!
I am totally new with Ash and I want to do a login action with a password verification,
Should I do an action or a function in my module ?
Marked As Solved
zachdaniel
Anonymous functions are just one way to define changes/preparations. You can use modules that implement the appropriate behavior.
prepare PreparationModule
....
validate ValidationModule
...
change ChangeModule
In all of those cases you can also add opts to reuse the behavior but customize per use.
change {SomeChange, opt: :value}
You can’t use a change as a preparation or a validation etc. so within those modules if you have to share logic you do it with “regular functions”. I.e if you want a function that takes a string and tells you if it’s a valid email, you can put that in a module alongside your resource and call into it from the resource.
Each of the ways of using those types of modules I mentioned above is explained in its respective guide: Changes — ash v3.4.56
The book also goes into this and how to use/think about it in detail.
Also Liked
zachdaniel
It is on the short list to allow validations to be run against queries, which will make this experience much nicer. i.e validate match(:email, ~r//), message: "..." For now, however, preparations is the only way. Sorry about that!







