Controller Function and Changeset for each attribute

I was taking a look at the new, and very welcome, gen_auth (https://github.com/aaronrenner/phx_gen_auth). 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 https://github.com/aaronrenner/phx_gen_auth/blob/master/priv/templates/phx.gen.auth/settings_edit.html.eex.

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?

1 Like

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.

3 Likes