title: Elixir Phoenix Plugs and where to place them
body: <p>I'm currently at learning Elixir Phoenix framework. I stuck at <a href="https://hexdocs.pm/phoenix/routing.html#forward" rel="nofollow noreferrer">https://hexdocs.pm/phoenix/routing.html#forward</a> now, it's about how to use <code>forward</code> command.</p>
  
  <p>It's written there, that it's not neccessary to learn about Plugs now, so if I want to try out that <code>forward</code> command I can just copy their implementation of Plug <strong>into my application</strong>. But where exactly? I tried to search it out and tried to use what I found, but I am doing something wrong.</p>
  
  <p>That's the scope from my <code>.\lib\hello_web\router.ex</code> file:</p>
  
  <pre><code>scope "/", HelloWeb do
    pipe_through :browser # Use the default browser stack
  
    get "/", PageController, :index
    forward "/jobs", BackgroundJob.Plug, name: "Hello, Phoenix"
  end
  </code></pre>
  
  <p>And that is the code for a Plug:</p>
  
  <pre><code>defmodule BackgroundJob.Plug do
    def init(opts), do: opts
    def call(conn, opts) do
      conn
      |&gt; Plug.Conn.assign(:name, Keyword.get(opts, :name, "Background Job"))
      |&gt; BackgroundJob.Router.call(opts)
    end
  end
  
  defmodule BackgroundJob.Router do
    use Plug.Router
  
    plug :match
    plug :dispatch
  
    get "/", do: send_resp(conn, 200, "Welcome to #{conn.assigns.name}")
    get "/active", do: send_resp(conn, 200, "5 Active Jobs")
    get "/pending", do: send_resp(conn, 200, "3 Pending Jobs")
    match _, do: send_resp(conn, 404, "Not found")
  end
  </code></pre>
  
  <p>I supposed to know almost nothing about Plugs and Phoenix at all at this point, so it is probably something obvious, but I really stuck there for hours. Can anyone help me to find out where to place that code?</p>