First I want to say I’m about to outline an issue with the video @chrismccord did, that said it’s still great he even created the video in the first place and I’m very grateful for his and everyone’s efforts. I realize it’s a learning experience for everyone and this is just a part of that process. So again thank you to everyone who contributes to this community and software. I feel I don’t say that enough.
Ok, so the issues:
There looks to be one critical issue with the design pattern used for setting the urls.
Using the put_image_urls
for the edit action won’t persist the db. This is a tricky one because ecto does not complain and the return value from calling Repo.update
even shows the correct data. The problem is the data never gets persisted to the db on update.
Take this for example. Note: Repo.update()
iex(1)> {:ok, %{id: id}} = %Post{ p | image_urls: ['foo']}
|> Post.changeset(%{})
|> Repo.update()
{:ok,
%Post{
id: 2,
image_urls: ['foo'],
...
}}
iex(2)> Post |> Repo.get(id)
%Post{
id: 2,
image_urls: [],
...
}
For Repo.insert()
the above would have persisted but not for update.
This leads me to the question,
Why are we not building up the post_params rather than directly on the post?
Maybe just an oversight?
I get this is outside the context of the example video showcasing how to do something with liveview, though I’m left wondering if I am overthinking how we pass in extra params like this and general design choices like this.