Hi,
I’m wondering if anyone can shed any light on this. I’m working through the Programming Phoenix book, and am enjoying myself so far - I’ve learned a whole bunch, it’s a great book.
Now, on page 102 I’m adding the following:
def new(conn, _params) do
changeset =
conn.assigns.current_user
|> build_assoc(:videos)
|> Video.changeset()
render(conn, "new.html", changeset: changeset)
end
The idea here - as I understand it - is to generate a changeset that ties the logged in user to the Video that will be created when the user submits their form.
What I don’t understand is why do this at all in “new” ?
It makes sense to me that this would be done on POST / in the “create” function. And reading ahead this association is repeated in the “create” function.
As best I can see, doing this in “new” has no impact on the generated HTML.
What am I missing here?
Any help gratefully appreciated.
Thanks,
Chris