Function Adding Args to Controller Actions

The source code actually updates all actions to 3 parameters.

For some more background

https://medium.com/@lostkobrakai/alternative-parameters-for-phoenix-controller-actions-edd2b8a4362a


This works:

defmodule D3jsDemoWeb.PageController do
  use D3jsDemoWeb, :controller

  def action(conn, _) do
    args = [conn, conn.params]
    apply(__MODULE__, action_name(conn), args)
  end

  def index(conn, _params) do
    render(conn, "index.html")
  end
end

This fails:

defmodule D3jsDemoWeb.PageController do
  use D3jsDemoWeb, :controller

  def action(conn, _) do
    args = [conn, conn.params. :ok]
    apply(__MODULE__, action_name(conn), args)
  end

  def index(conn, _params) do
    render(conn, "index.html")
  end
end

with

UndefinedFunctionError at GET /
function D3jsDemoWeb.PageController.index/3 is undefined or private

on the index action when rendering the page - which is the behaviour I would have expected if you left def index(conn, _params) do in place for that controller after adding the third parameter in the action function.

after

defmodule D3jsDemoWeb.PageController do
  use D3jsDemoWeb, :controller

  def action(conn, _) do
    args = [conn, conn.params, :ok]
    apply(__MODULE__, action_name(conn), args)
  end

  def index(conn, _params, _other) do
    render(conn, "index.html")
  end
end

everything works again.