peck

peck

Controller Function and Changeset for each attribute

I was taking a look at the new, and very welcome, gen_auth (GitHub - aaronrenner/phx_gen_auth: An authentication system generator for Phoenix 1.5 applications. · GitHub). I’m excited that it is out there and it is going to do a lot of help people getting projects off the ground.

I did notice that the library does something a little differently than I have done before. There are different controller functions, and different change sets for each attribute. I found this interesting as I’m generally just had an update function in my controller that generated a single changeset to pass out to the eex forms phx_gen_auth/priv/templates/phx.gen.auth/settings_edit.html.eex at master · aaronrenner/phx_gen_auth · GitHub.

I was wondering if this is something that you all do as well, or if @josevalim, @aaronrenner and the other library authors did it mostly for the explicitness and being able to do the flash messages. I’m adding this to one of my applications now, but my User has additional fields like an avatar, nickname, etc. I appreciate the explicitness but Im looking at all these other fields and Im thinking that I don’t really want to have a changeset/controller action for each one.

What approach do you all take?

Marked As Solved

josevalim

josevalim

Creator of Elixir

You should create as many changesets as necessary but not more. The reason why email and password have their own changesets is because updating each of them has their own security requirements. But all other fields would be fine to be updated together. If your resource has the same fields on insert and update, then there is no need for two changesets either.

Where Next?

Popular in Discussions Top

ben-pr-p
In general I’ve been sticking to this community style guide GitHub - christopheradams/elixir_style_guide: A community driven style guide ...
New
und0ck3d
Hello everyone! A few days ago I’ve created a topic here about how people were creating CMSs with Elixir and Phoenix. I’ve been studying...
New
pdgonzalez872
If this has been asked here before, please point me to where it was asked as I didn’t find it when I searched the forum. Maybe a mailing ...
New
mikl
I wanted to capitalize a string, and tried using String.capitalize(). That generally works well, until you try to capitalize a word like...
New
opsb
We’re considering our architecture from a viewpoint of scaling our traffic heavily over the next 6 months. Our current deployment is runn...
New
marciol
Please, let me know if this kind of discussion already took place in another topic . Hi all, how do you consider if is better to build ...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
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
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
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
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New

We're in Beta

About us Mission Statement