Programming Phoenix book regex "undefined function content/2" compilation error

In the Programming Phoenix book, in the “Watching Videos” chapter, there is a regex used in file watching_videos/listings/rumbl/lib/rumbl_web/views/watch_view.ex that looks like this:


but when I use it my compiler and LSP both complain:

== Compilation error in file lib/rumbl_web/views/watch_view.ex ==
** (CompileError) lib/rumbl_web/views/watch_view.ex:6: undefined function content/2
    (elixir) src/elixir_locals.erl:107: :elixir_locals."-ensure_no_undefined_local/3-lc$^0/1-0-"/2
    (elixir) src/elixir_locals.erl:107: anonymous fn/3 in :elixir_locals.ensure_no_undefined_local/3
    (stdlib) erl_eval.erl:680: :erl_eval.do_apply/6
    (elixir) lib/kernel/parallel_compiler.ex:208: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6

Can somebody please explain what is happening, why this regex raises an undefined function content/2 error? I feel like I must be missing something obvious but the error does not make any sense to me.

Hello, welcome.

Please show the full watch_view.ex file, like this, it just look like a normal regex.

I tried writing it with just a normal string and the problem is the same . I must have messed something up but I cannot make sense of the error message.

Copied and pasted from the book:

defmodule RumblWeb.WatchView do
  use RumblWeb, :view

  def player_id(video) do
    |> Regex.named_captures(video.url)
    |> get_in(["id"])

It works well in the console, as You can see…

iex(2)> url = ""
iex(3)> regex = ~r{^.*(?:youtu\.be/|\w+/|v=)(?<id>[^#&?]*)}
iex(4)> Regex.named_captures(regex, url) |> get_in(["id"])

My bet is to watch in the template show.html.eex…

<%= content_tag :div, id: "video",
data: [id:, player_id: player_id(@video)] do %>
<% end %>

Can You show this template?

here is the template:

<div class="row">

  <div class="column column-60">
    <h1><%=  @video.title %></h1>

    <%=  content tag :div, id: "video",
    data: [id:, player_id: player_id(@video)] do %>
    <% end %>


  <div class="column annotations" >

    <div id="msg-container"></div>

      <textarea id="msg-input"

      <button id="msg-submit" class="button column" type="submit">



It’s content_tag, not content tag


i knew it was something stupid. Thanks for the help and sorry for wasting your time. :slight_smile:

We all do mistakes :slight_smile:

But You should try to test in the console, it’s a useful debugging tool.

1 Like

ok i will