I want to display a list of article_categories in an article form (used for creation and update) as a drop down input.
I have a function in my blog context (blog.ex) to retrieve all categories through Ecto and format the result as a drop-downable list:
defmodule MyApp.Blog do
import Ecto.Query, warn: false
alias MyApp.Repo
alias MyApp.Blog.ArticleCategory
def get_categories() do
MyApp.Repo.all from c in ArticleCategory, select: {c.title, c.id}
end
end
In my template (templates/article/form.html.heex) I call my categories like this:
<%= select f, :category_id, MyApp.Blog.get_categories(), prompt: [key: "Choose your category"] %>
Visually I get the result I want, BUT... the literature seems to hint at passing my categories as an assign.
Is there an issue in doing it this way? (performance? design?)