Skip to Main Content
Mastering Elixir
book

Mastering Elixir

by André Albuquerque, Daniel Caixinha
July 2018
Intermediate to advanced content levelIntermediate to advanced
574 pages
14h 7m
English
Packt Publishing
Content preview from Mastering Elixir

Handling requests in a controller

At this point, the request is in the controller, which was called by the router according to the logic we described. We'll build the FileController that we saw in the router, and go through the four actions we've created routes for: index, show, new. and create. Let's begin with the index action:

$ cat apps/elixir_drip_web/lib/elixir_drip_web/controllers/file_controller.exdefmodule ElixirDripWeb.FileController do  use ElixirDripWeb, :controller  alias ElixirDrip.Storage  def index(conn, %{"path" => path}) do    with {:ok, media} <- Storage.media_by_folder("hardcoded_user_id",     path) do      render(conn, "index.html", files: media.files, folders:       media.folders, current_path: path)    else      {:error, :invalid_path} -> conn ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Testing Elixir

Testing Elixir

Andrea Leopardi, Jeffrey Matthias

Publisher Resources

ISBN: 9781788472678Supplemental Content