1

In my live view template I added this snippet:

  <script src="<%= Routes.static_path(@socket, "/js/hi.js") %>"></script>

That produced the following error: enter image description here

How can I fix this?

ijt
  • 3,505
  • 1
  • 29
  • 40

1 Answers1

2

I got it working by replacing

  use Phoenix.LiveView

with

  use MyAppWeb, :live_view

in watch_live.ex.

ijt
  • 3,505
  • 1
  • 29
  • 40
  • 1
    `Routes` is just an alias for `MyAppWeb.Router.Helpers`. You could have kept `use Phoenix.LiveView` and changed `Routes` to `MyAppWeb.Router.Helpers`. You can see this alias in the `def view` block in your `my_app_web.ex` file. – Peaceful James Feb 24 '21 at 07:31