What is the troubleshooting path? Error compiling

Hello.

This a newbie question. I am just going through the step by step sample application in Programming Phoenix (by Chris McCord, Bruce Tate, and José Valim). I am on chapter nine. I am trying to compile the application but I am getting this:

== Compilation error on file web/views/video_view.ex ==
** (CompileError) web/templates/video/index.html.eex:23: undefined function watch_path/3
(stdlib) lists.erl:1338: :lists.foreach/2
(stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
(elixir) lib/kernel/parallel_compiler.ex:117: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/1

So, pretty clear error, right? there is no watch_path function with an arity of three. Silly me I can’t find the error though. View video view simply renders an index template:

defmodule Rumbl.VideoView do
use Rumbl.Web, :view
end

Line 23 of index:

<%= link “Watch”, to: watch_path(@conn, :show, video), class: “btn btn-default btn-xs” %>

What would be the next step backwards I need to look for the missing piece here? I apologise if the question is way too simple, I am most likely missing something but I cannot see what it is.

Basically I am asking what is the troubleshooting path I should follow.

Many thanks.

Maybe you need a route with :show action for WatchController defined in your router.ex?

get "/watch/:id", WatchController, :show

and in the watch controller

def show(conn, %{"id" => id}) do
  video = Repo.get!(Rumbl.Video, id)
  render conn, "show.html", video: video
end
1 Like

Path_helpers are generated dynamically based on your routes and controllers. That was a bit confusing to me when I started out as well. The documentation does a good job of explaining them.

Running mix phoenix.routes is helpful in seeing what helpers you currently have available with your routes.

1 Like

Just in case, the same docs but for phoenix 1.3.0-rc can be found on hexdocs https://hexdocs.pm/phoenix/1.3.0-rc.2/routing.html

I actually do have it exactly as you suggest in my router.ex and watch controller:

get "/", PageController, :index
resources "/users", UserController, only: [:index, :show, :new, :create]
resources "/sessions", SessionController, only: [:new, :create, :delete]
get "/watch/:id", WatchController, :show

and:

def show(conn, %{“id” => id}) do
video = Repo.get!(Video, id)
render conn, “show.html”, video: video
end

Thanks very much for the reply.

Thank you @Harold for the suggestion. I’ll look into this with more detail.

Maybe try comparing your code with https://github.com/terakilobyte/rumbl or some other github repo which can be found by googling “github:programming phoenix”.

I think you can also download some code from https://pragprog.com/titles/phoenix/source_code.

Right, I actually did that already before posting my question and could not find any difference between the book source code and mine. I’ll try this weekend to untangle it :grinning:. Thank you for the suggestion, I appreciate it.

Can you link to your entire video_view.ex?

One reason it might not be working is that there is a missing “import Rumbl.Router.Helpers” (or if using phoenix 1.3: “import Rumbl.Web.Router.Helpers”). without that, it won’t know what watch_path is supposed to resolve to as there is no watch_path function defined.

… but without seeing your video_view.ex in whole it is a bit harder to guess at what a solution might be.

Hi @aseigo,

This is my whole video_view.ex:

defmodule Rumbl.VideoView do
use Rumbl.Web, :view
end

It simple defines a view for the default Rumbl.Web which in turn actually imports Rumbl.Router.Helpers. This is a extract:

def controller do
quote do
use Phoenix.Controller

  alias Rumbl.Repo
  import Ecto
  import Ecto.Query, only: [from: 1, from: 2]
  import Rumbl.Router.Helpers
  import Rumbl.Gettext
  import Rumbl.Auth, only: [authenticate_user: 2] #New import
end

end

Thanks very much for your reply

What is the output of mix phoenix.routes?