Programming Phoenix 1.4 book examples updated to 1.7

Hello,

I am almost done going through the book, Programming Phoenix 1.4, again after a hiatus from using Elixir for a few years.

It seems that Phoenix has changed a lot since I last used it around version 1.2, especially the view layer with Phoenix.Component and HEEx templates.

I did my best to get caught up and translated the examples from the book using the new view layer style with components.

You can find my work on GitLab here:

My style is a little different from the authors, but hopefully the examples are close enough to get you unstuck. Please don’t mind the commit messages as I leave breadcrumbs for me to remember things when I come back to this work and refresh my memory.

I am posting here about it, because I thought maybe someone else might be working through the book, and could use some help translating from old to new. I hope folks find this useful, until the book has a chance to be updated.

I hope you’re having a nice day.

17 Likes

Thank you for posting this, it’s extremely helpful for people learning Phoenix. Mis-match between the code in the book and the current version is frustrating, great work!

1 Like

Thanks for posting this, @jramnani!

Does category input select in lib/rumbl_web/controllers/video_html/video_form.html.heex work fine for you?

When I use your code as is, the select neither has the proper value selected when opening edit video page, nor the changeset contains changed category_id when I save updated video.

When I use value={f.data.category_id}, the form has category value properly selected when opening edit video page, but still the changeset does not contain changed category_id when I save updated video.

Replacing

<.input
  field={{f, :category_id}}
  name="category"
  type="select"
  label="Categories"
  prompt="Enter a category"
  options={Enum.map(@categories, fn c -> {c.name, c.id} end)}
  value={Enum.map(@categories, fn c -> c.id end)}
  />

from here with

<.input
  field={f[:category_id]}
  type="select"
  label="Categories"
  prompt="Enter a category"
  options={Enum.map(@categories, fn c -> {c.name, c.id} end)}
  />

is what fixed the problem on Phoenix 1.7.7 for me.