clifinger

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

zachdaniel

Creator of Ash

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.29.3

The book also goes into this and how to use/think about it in detail.

Also Liked

zachdaniel

zachdaniel

Creator of Ash

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!

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement