Use Elixir plug for only some controller actions
Phoenix allows for a flexible request processing pipeline with plugs. Your
controllers are basically plugs in the plug pipeline. You can specify plugs that will execute before your controller actions with the plug
macro.
defmodule MyApp.ThingController do
use MyApp.Web, :controller
plug MyApp.InterestingPlug
end
You can also specify a guard for this macro that will only enable this plug to be run before certain actions:
plug MyApp.InterestingPlug when action in [:new, :create]
Tweet