I’m reading Phoenix for Rails developers book and the following line raises a compilation exception:
<%= link to: book_path(@conn, :show, book.id) do %>
Show
<% end %>
The compilation error stack trace:
== Compilation error in file lib/storex_web/views/book_view.ex ==
** (CompileError) lib/storex_web/templates/book/index.html.eex:17: undefined function book_path/3
(elixir) src/elixir_locals.erl:108: :elixir_locals."-ensure_no_undefined_local/3-lc$^0/1-0-"/2
(elixir) src/elixir_locals.erl:109: 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:229: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/7
What’s wrong with that syntax? I do have the needed route defined:
#router.ex
scope "/", StorexWeb do
pipe_through :browser
get "/", BookController, :index
get "/books/:id", BookController, :show
end
and the routes are well defined:
book_path GET / StorexWeb.BookController :index
book_path GET /books/:id StorexWeb.BookController :show
websocket WS /socket/websocket StorexWeb.UserSocket
Thank you.