Followed the following steps from programming-phoenix-liveview book mix phx.new pento
mix phi.server works as expected
Then added the following to router.ex
scope "/", PentoWeb do
pipe_through :browser
get "/", PageController, :index
live "/guess", WrongLive
end
created file live/wrong_live.ex with the following content
defmodule PentoWeb.WrongLive do
use Phoenix.LiveView, layout: {PentoWeb.LayoutView, "live.html"}
def mount(_params, _session, socket) do
{:ok, assign(socket, score: 0, message: "Make a guess:")}
end
def render(assigns) do
~H"""
<h1>Your score: <%= @score %></h1>
<h2>
<%= @message %>
</h2>
<h2>
<%= for n <- 1..10 do %>
<a href="#" phx-click="guess" phx-value-number= {n} ><%= n %></a>
<% end %>
</h2>
"""
end
end
Once I restart the server localhost:4000/guess is supposed to show the live view, but I get the Not found
You could confirm with mix phx.routes which should list all the configured routes including a live_path GET /guess ... and perhaps confirm there are no compilation errors by restarting the server?
Is live/wrong_live.ex inside <pento-project>/lib/pento_web/live/wrong_live.ex (correct) or <pento-project>/live/wrong_live.ex (incorrect)? Code needs to be inside lib.
Or makes sure you’re not accidentally working on a different project folder by accident.