
jshprentz
Programming Phoenix LiveView B10.0: Demographic display logic explanation does not match code (page 221)
The second paragraph on page 221 describes the demographic display logic:
… If no demographic exists, and the socket assigns key of
:demographic
points tonil
, the template renders the demographic form. Otherwise, we render the demographic show component and call on theRatingLive.Index.products/1
function component to add the product ratings to our view.
The logic in survey_live.html.heex
is reversed. The code tests for the existence of @demographic
rather than it’s non-existence:
<%= if @demographic do %>
<DemographicLive.Show.details demographic={@demographic} />
<hr />
<br/>
<RatingLive.Index.product_list products={@products}
current_user={@current_user} />
<% else %>
<!-- ... -->
<% end %>
Also, the first sentence shown above contains the phrase “points to nil
.” Earlier, on page 197, the book used the phrase “set to nil
”:
So, the
:demographic
key in socket assigns could be set to a demographic struct, or it could be set tonil
.
Could the description be reordered to match the code? Perhaps:
… If a demographic exists, the
:demographic
key in socket assigns will be set to a demographic struct; the template renders the demographic show component and calls theRatingLive.Index.products/1
function component to add the product ratings to our view. Otherwise, the:demographic
key in socket assigns will be set tonil
; the template renders the demographic form.
Marked As Solved

SophieDeBenedetto
Indeed it could! This will be updated before the final release.
Popular Prag Prog topics










Modern front-end development for Rails, second edition - Struggling to get the first chapter to work
Other popular topics










Latest in PragProg
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /centos
- /ash
- /php
- /deepseek
- /zig
- /scala
- /html
- /debian
- /nixos
- /lisp
- /agda
- /sublime-text
- /textmate
- /react-native
- /kubuntu
- /arch-linux
- /ubuntu
- /revery
- /manjaro
- /spring
- /django
- /diversity
- /nodejs
- /lua
- /slackware
- /c
- /julia
- /neovim