I want to create an HTML resource of posts, and I’m watching this tutorial
A lot of things are outdated because it was made in 2017.
One thing that I’m having some issues to understand is this command:
mix phx.gen.html [Context] [Schema name] [Table name] [Fields] ...
mix phx.gen.html Articles Post posts title:string body:text
What I know is that it will generate views and controllers for a HTML resource but the definition of context isn’t clear for me.
They have a full page in the guides about contexts:
Basically, its a module providing functions which shall then interact with ecto, rather than dealing with ecto directly in your controller or, even worse, your view.
Basically, it is meant to abstract your datastorage away, such that your context functions could also make HTTP requests against a REAT-API rather than a database or fetch cached data from memory.
Contexts are to Controllers how Presenters are to Views.
Presenters encompass all the stuff that the view will consume.
Contexts encompass all the stuff that the controller will consume.