- LiveView is a SSR library for Phoenix
- Absinthe is a library for phoenix that provides GraphQL, here are Install Absinthe in a Phoenix project
Adding authentication to a Phoenix Webframework Application hacks
- Added dependency to application
{:phx_gen_auth, "~> 0.6", only: [:dev], runtime: false},- mix phx.gen.auth Account User users
- Updated and committed files as needed
- Fixed test suite
Collapsing Migrations and Schema dumping hacks
Run ecto.dump to dump the schema file at priv/repo/structure.sql. Commit the file and modify the the aliases section of mix.exs to run ecto.load --skip-if-loaded --quiet1.
--- a/mix.exs
+++ b/mix.exs
"cmd npm --prefix assets install",
"cmd npm --prefix assets run deploy"
],
- "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
+ "ecto.setup": ["ecto.create", "ecto.load --skip-if-loaded --quiet", "ecto.migrate", "run priv/repo/seeds.exs"],
"ecto.reset": ["ecto.drop", "ecto.setup"],
test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"],
"assets.deploy": [Notes on framework
connection
|> endpoint()
|> plug()
|> plug()
...
|> router()
|> HelloWebController()lib/app_name/application.ex has the logic for starting, stopping, and supervising each application lib/app_name_web/endpoint.ex: beginning of the web logic
“Generally speaking, a context encapsulates all business logic for a common purpose. This way, we can interact with our business logic from controllers, channels or remote APIs, without having to duplicate code. In a nutshell, a controller exists to work with context functions. It parses end user requests, calls context functions and translates those results into something the end user can understand. Each slice of code has an isolated purpose. The context doesn’t know about the controller, and the controller doesn’t know about the business rules.”
– Form Programming Phoenix2
Rails Console equivalent
iex -S mixRendering Pathway
Router: define pipelines and routes -> Controller: functional logic before view -> View: render template -> Template: .eex extension
Releases
- Historically, releases were served by distillery a third party utility that packaged the web app up as a tar ball. This was replaced by a native elixir solution via mix release in elixir 1.9.
Deployment
Deploy a Phoenix app with Docker stack
Install phoenix simply on macOS
brew install elixir
mix local.hex
mix archive.install phx_new
Embedded forms and inputs_for handling in Liveview > 1.7
This is a useful blog post for explaining how to deal with nested inputs in a Live View form.