Programming Phoenix LiveView: P27, live_path confusion

I am working on the “Your Turn” for chapter one and building out the restart button talked about on page 27. It recommends looking into the live_patch function to patch the view and add the button. Many examples involving live_patch I found on the web suggested something like

<%= live_patch to: Routes.live_path(@socket, __MODULE__), replace: true do %>
   <button>Try again!</button>
<%end>

but Elixir complains with

warning: Routes.live_path/2 is undefined (module Routes is not available or is yet to be defined)
  lib/pento_web/live/wrong_live.ex:50: PentoWeb.WrongLive.render/1

mix phx.routes says the helper is defined:

$ mix phx.routes
          page_path  GET  /                                      Phoenix.LiveView.Plug :index
          live_path  GET  /guess                                 Phoenix.LiveView.Plug PentoWeb.WrongLive
live_dashboard_path  GET  /dashboard                             Phoenix.LiveView.Plug :home
live_dashboard_path  GET  /dashboard/:page                       Phoenix.LiveView.Plug :page
live_dashboard_path  GET  /dashboard/:node/:page                 Phoenix.LiveView.Plug :page
          websocket  WS   /live/websocket                        Phoenix.LiveView.Socket
           longpoll  GET  /live/longpoll                         Phoenix.LiveView.Socket
           longpoll  POST  /live/longpoll                         Phoenix.LiveView.Socket
          websocket  WS   /socket/websocket                      PentoWeb.UserSocket

So I must be missing a use or alias somewhere? Help?

2 Likes