Hi guys. I took a break on coding for a while and coming back to my code base I got confused (maybe I’m getting old ha).
So I have a plug code that works with a controller index.
The idea is that the company controller index will get a list of companies using the query select * from companies
kinda deal. The plug is handling this list of companies.
My question is where do you specify that this plug belong to the company controller? Or did I accidentally made it run this query for every user request (irregardless to a specific controller)? Thank you for you time.
Here’s all the relevant code I can think of:
Controller:
defmodule FumigateWeb.CompanyController do
use FumigateWeb, :controller
alias Fumigate.Fragrance
def index(conn, params) do
params = Map.put(params, :page_size, 25)
page = Fragrance.list_companies_paginate(params)
render(conn, "index.html", page: page)
end
Plug
defmodule Fumigate.Plug.CompanyList do
import Plug.Conn
alias Fumigate.Fragrance
def init(opts), do: opts
def call(conn, _opts) do
assign(conn, :companies, Fragrance.list_alphabetical_companies())
end
end