peck

peck

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?

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

gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39247 209
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
crabonature
I’m still quite new to Elixir. As I understand we got in Elixir “multi guards” as convention to simplify one large guard with or’s?: de...
New
sashaafm
Piggy backing a bit on @dvcrn topic BEAM optimization for functions with static return type?, I’ve been trying to understand in a deeper ...
New
fireproofsocks
I’ve been working on an Elixir project that has required a lot of scripting. I usually reach for Elixir because I like it more (and in th...
New
rms.mrcs
A couple of days ago I was discussing with a friend about different approaches to write microservices. He said that if he was going to w...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
tomekowal
Hey guys! I want to create a toy project that shows a chart of temperature over time and updates every 5 seconds. I feel LiveView is per...
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
Markusxmr
Since Drab has been developed for a while in the open, introducing the Liveview functionality in a way it happend appears to undermine th...
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
RisingFromAshes
I've read in another post that it may be possible with a router helper - but I couldn't find an appropriate one, and tbh, I'm still just ...
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
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35953 110
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
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31107 143
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

We're in Beta

About us Mission Statement