A common occurance in my phoenix applications is the need to render a list of some items โ say companies in a job board application. Letโs start out simple by using the phoenix generators to build up the first bunch of boilerplate for those companies:
$ mix phx.gen.live JobBoard Company companies name:string website:string
This does generate a liveview module
MyAppWeb.CompanyLive.Index
, which for the liveaction:index
can render a nice list of companies.But usually things do not stop here. Letโs say the next requirement is adding the number of jobs published per company in that table on the index page. A quick look into the liveview module will reveal that it calls into its related context module to fetch companiesโ data for rendering.
def list_companies() do Repo.all(Company) end
continue reading on kobrakai.de
โ ๏ธ This post links to an external website. โ ๏ธ
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.