Created
September 18, 2015 00:06
-
-
Save chrismccord/faf9449aa44432bc8654 to your computer and use it in GitHub Desktop.
catch-all action
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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