Skip to content

Instantly share code, notes, and snippets.

@chrismccord
Created September 18, 2015 00:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismccord/faf9449aa44432bc8654 to your computer and use it in GitHub Desktop.
Save chrismccord/faf9449aa44432bc8654 to your computer and use it in GitHub Desktop.
catch-all action
defmodule MyApp.Web do
def controller do
quote do
use Phoenix.Controller
use MyApp.CatchAllController
...
end
end
end
defmodule MyApp.CatchAllController do
defmacro __using__(_opts) do
quote do
@before_compile unquote(__MODULE__)
end
end
defmacro __before_compile__(_env) do
for action <- [:new, :edit, :show, :index, :update, :delete] do
quote do
def unquote(action)(conn, _params) do
Plug.Conn.send_resp(conn, 400, "")
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment