
okari5678
Programming Phoenix LiveView:
socket is being accessed in the function body, hence the need to include it in the function head.
Current:
def maybe_track_user(
-
product,*
-
%{assigns: %{live_action: :show, user_token: user_token}}*
-
) do*
-
if connected?(socket) do*
-
user = Accounts.get_user_by_session_token(user_token)*
-
# do tracking here!*
- end*
Expected:
def maybe_track_user(
-
product,*
-
%{assigns: %{live_action: :show, user_token: user_token}} **= socket***
-
) do*
-
if connected?(socket) do*
-
user = Accounts.get_user_by_session_token(user_token)*
-
# do tracking here!*
end
Title: Programming Phoenix LiveView: B3.0: Include “=socket” in function header (page 255)
Example: Programming Flutter - ‘pub get’ command not working (page 15)
Please also add the book’s tag if it has not already present, thanks!
Marked As Solved

SophieDeBenedetto
Author of Programming Phoenix LiveView
Hi! Thanks for submitting your question. It does in fact look like there is a mistake in that code! The correct case
statement should read like this:
case Presence.get_by_key("user_activity", product.name) do
[] ->
Presence.track(
pid,
"user_activity",
product.name, %{users: [%{email: user.email}]}
)
%{metas: [%{users: active_users_for_product}]} ->
Presence.update(pid, "user_activity", product.name, %{
users: [active_users_for_product | %{email: user.email}]
})
end
You’ll find that updated in the next Beta release. In the meantime, you can copy in the correction from this comment.
Popular Pragmatic Bookshelf topics

Hi everyone!
There is an error on the page 71 in the book “Programming machine learning from coding to depp learning” P. Perrotta. You c...
New

Hi Travis! Thank you for the cool book! :slight_smile:
I made a list of issues and thought I could post them chapter by chapter. I’m rev...
New

Hi! I know not the intentions behind this narrative when called, on page XI:
mount() |> handle_event() |> render()
but the correc...
New

I found an issue in Chapter 7 regarding android:backgroundTint vs app:backgroundTint.
How to replicate:
load chapter-7 from zipfile i...
New

Hi,
I completed chapter 6 but am getting the following error when running:
thread 'main' panicked at 'Failed to load texture: IoError(O...
New

On page 78 the following code appears:
<%= link_to ‘Destroy’, product,
class: ‘hover:underline’,
method: :delete,
data: { confirm...
New

It seems the second code snippet is missing the code to set the current_user:
current_user: Accounts.get_user_by_session_token(session["...
New

@mfazio23
I’m following the indications of the book and arriver ad chapter 10, but the app cannot be compiled due to an error in the Bas...
New

I got this error when executing the plot files on macOS Ventura 13.0.1 with Python 3.10.8 and matplotlib 3.6.1:
programming_ML/code/03_...
New

I just bought this book to learn about Android development, and I’m already running into a major issue in Ch. 1, p. 20: “Update activity...
New
Other popular topics

Reading something? Working on something? Planning something? Changing jobs even!?
If you’re up for sharing, please let us know what you’...
New

Do the test and post your score :nerd_face:
:keyboard:
If possible, please add info such as the keyboard you’re using, the layout (Qw...
New

If you are experiencing Rails console using 100% CPU on your dev machine, then updating your development and test gems might fix the issu...
New

We’ve talked about his book briefly here but it is quickly becoming obsolete - so he’s decided to create a series of 7 podcasts, the firs...
New

Author Spotlight
James Stanier
@jstanier
James Stanier, author of Effective Remote Work , discusses how to rethink the office as we e...
New

Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New

Author Spotlight
Mike Riley
@mriley
This month, we turn the spotlight on Mike Riley, author of Portable Python Projects. Mike’s book ...
New
New

Author Spotlight:
Karl Stolley
@karlstolley
Logic! Rhetoric! Prag! Wow, what a combination. In this spotlight, we sit down with Karl ...
New

This is a very quick guide, you just need to:
Download LM Studio: https://lmstudio.ai/
Click on search
Type DeepSeek, then select the o...
New
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /rails
- /js
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /ash
- /vscode
- /opensuse
- /centos
- /php
- /deepseek
- /html
- /zig
- /scala
- /debian
- /nixos
- /lisp
- /agda
- /textmate
- /sublime-text
- /react-native
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /django
- /spring
- /manjaro
- /diversity
- /nodejs
- /lua
- /julia
- /slackware
- /c
- /neovim