bodyguard
bodyguard copied to clipboard
Readme example confusion
In the readme in the Plugs section I see the following code:
defp get_post(conn, _) do
assign(conn, :post, MyApp.Posts.get_post!(conn.params["id"]))
end
# Helper for the Authorize plug
def extract_post(conn), do: conn.assigns.posts
My confusion is how does posts become an element of assigns?
at the top there is a plug
# Fetch the post and put into conn assigns
plug :get_post when action in [:show]
so before executing :show, first this plug is run which assigns the post to the connection.